home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_automake.idb / usr / freeware / bin / automake.z / automake
Encoding:
Text File  |  1999-07-16  |  191.2 KB  |  7,229 lines

  1. #!/usr/freeware/bin/perl
  2. # -*- perl -*-
  3. # Generated automatically from automake.in by configure.
  4.  
  5. eval 'exec /usr/freeware/bin/perl -S $0 ${1+"$@"}'
  6.     if 0;
  7.  
  8. # automake - create Makefile.in from Makefile.am
  9. # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  10.  
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2, or (at your option)
  14. # any later version.
  15.  
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20.  
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. # 02111-1307, USA.
  25.  
  26. # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
  27. # Perl reimplementation by Tom Tromey <tromey@cygnus.com>.
  28.  
  29.  
  30. # Parameters set by configure.  Not to be changed.  NOTE: assign
  31. # VERSION as string so that eg version 0.30 will print correctly.
  32. $VERSION = "1.4";
  33. $PACKAGE = "automake";
  34. $prefix = "/usr/freeware";
  35. $am_dir = "${prefix}/share/automake";
  36. $TAR = "tar";
  37.  
  38. # String constants.
  39. $IGNORE_PATTERN = "^##([^#].*)?\$";
  40. $WHITE_PATTERN = "^[ \t]*\$";
  41. $COMMENT_PATTERN = "^#";
  42. $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$";
  43. $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z]+)\\.([a-zA-Z]+)\$";
  44. $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
  45. $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)\$";
  46. $GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";
  47. $IF_PATTERN = "^if[ \t]+\([A-Za-z][A-Za-z0-9_]*\)[ \t]*\(#.*\)?\$";
  48. $ELSE_PATTERN = "^else[ \t]*\(#.*\)?\$";
  49. $ENDIF_PATTERN = "^endif[ \t]*\(#.*\)?\$";
  50. $PATH_PATTERN='(\\w|/|\\.)+';
  51. # This will pass through anything not of the prescribed form.
  52. $INCLUDE_PATTERN = "^include[ \t]+((\\\$\\\(top_srcdir\\\)/${PATH_PATTERN})|(\\\$\\\(srcdir\\\)/${PATH_PATTERN})|([^/\\\$]${PATH_PATTERN}))[ \t]*(#.*)?\$";
  53.  
  54. # Some regular expressions.  One reason to put them here is that it
  55. # makes indentation work better in Emacs.
  56. $AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
  57. $AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^,)]+)[,)]";
  58. $AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
  59. # Note that there is no AC_PATH_TOOL.  But we don't really care.
  60. $AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?(\\w+)";
  61. $AM_MISSING_PATTERN = "AM_MISSING_PROG\\(\\[?(\\w+)";
  62. # Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
  63. # then too bad.
  64. $AC_SUBST_PATTERN = "AC_SUBST\\(\\[?(\\w+)";
  65. $AM_CONDITIONAL_PATTERN = "AM_CONDITIONAL\\((\\w+)";
  66.  
  67. # Constants to define the "strictness" level.
  68. $FOREIGN = 0;
  69. $GNU = 1;
  70. $GNITS = 2;
  71.  
  72.  
  73.  
  74. # Variables global to entire run.
  75.  
  76. # TRUE if we should always generate Makefile.in.
  77. $force_generation = 1;
  78.  
  79. # Strictness level as set on command line.
  80. $default_strictness = $GNU;
  81.  
  82. # Name of strictness level, as set on command line.
  83. $default_strictness_name = 'gnu';
  84.  
  85. # This is TRUE if GNU make specific automatic dependency generation
  86. # code should be included in generated Makefile.in.
  87. $cmdline_use_dependencies = 1;
  88.  
  89. # This is the name of a dependency makefile bit (usually for inclusion in a
  90. # SMakefile or similar); empty if not set.
  91. $generate_deps = '';
  92.  
  93. # TRUE if in verbose mode.
  94. $verbose = 0;
  95.  
  96. # This holds our (eventual) exit status.  We don't actually exit until
  97. # we have processed all input files.
  98. $exit_status = 0;
  99.  
  100. # From the Perl manual.
  101. $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
  102.  
  103. # TRUE if missing standard files should be installed.
  104. $add_missing = 0;
  105.  
  106. # TRUE if we should copy missing files; otherwise symlink if possible.
  107. $copy_missing = 0;
  108.  
  109. # Files found by scanning configure.in for LIBOBJS.
  110. %libsources = ();
  111.  
  112. # True if AM_C_PROTOTYPES appears in configure.in.
  113. $am_c_prototypes = 0;
  114.  
  115. # Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
  116. # name which appears in AC_CONFIG_HEADER, colon and all.
  117. # @config_names holds the file names.  @config_headers holds the '.in'
  118. # files.  Ordinarily these are similar, but they can be different if
  119. # the weird "NAME:FILE" syntax is used.
  120. @config_fullnames = ();
  121. @config_names = ();
  122. @config_headers = ();
  123. # Line number at which AC_CONFIG_HEADER appears in configure.in.
  124. $config_header_line = 0;
  125.  
  126. # Directory where output files go.  Actually, output files are
  127. # relative to this directory.
  128. $output_directory = '.';
  129.  
  130. # Relative location of top build directory.
  131. $top_builddir = '';
  132.  
  133. # Absolute location of top build directory.
  134. $build_directory = '';
  135.  
  136. # Name of srcdir as given in build directory's Makefile.  For
  137. # dependencies only.
  138. $srcdir_name = '';
  139.  
  140. # List of Makefile.am's to process, and their corresponding outputs.
  141. @input_files = ();
  142. %output_files = ();
  143.  
  144. # List of files in AC_OUTPUT without Makefile.am, and their outputs.
  145. @other_input_files = ();
  146. # Line number at which AC_OUTPUT seen.
  147. $ac_output_line = 0;
  148.  
  149. # List of directories to search for configure-required files.  This
  150. # can be set by AC_CONFIG_AUX_DIR.
  151. @config_aux_path = ('.', '..', '../..');
  152. $config_aux_dir = '';
  153.  
  154. # Whether AC_PROG_MAKE_SET has been seen in configure.in.
  155. $seen_make_set = 0;
  156.  
  157. # Whether AM_GNU_GETTEXT has been seen in configure.in.
  158. $seen_gettext = 0;
  159. # Line number at which AM_GNU_GETTEXT seen.
  160. $ac_gettext_line = 0;
  161.  
  162. # Whether ALL_LINGUAS has been seen.
  163. $seen_linguas = '';
  164. # The actual text.
  165. $all_linguas = '';
  166. # Line number at which it appears.
  167. $all_linguas_line = 0;
  168.  
  169. # 1 if AC_PROG_INSTALL seen.
  170. $seen_prog_install = 0;
  171.  
  172. # Whether AC_PATH_XTRA has been seen in configure.in.
  173. $seen_path_xtra = 0;
  174.  
  175. # TRUE if AC_DECL_YYTEXT was seen.
  176. $seen_decl_yytext = 0;
  177.  
  178. # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
  179. # AC_CHECK_TOOL also sets this.
  180. $seen_canonical = 0;
  181.  
  182. # TRUE if we've seen AC_ARG_PROGRAM.
  183. $seen_arg_prog = 0;
  184.  
  185. # TRUE if we've seen AM_PROG_LIBTOOL.
  186. $seen_libtool = 0;
  187. $libtool_line = 0;
  188.  
  189. # Files installed by libtoolize.
  190. @libtoolize_files = ('ltconfig', 'ltmain.sh', 'config.guess', 'config.sub');
  191.  
  192. # TRUE if we've seen AM_MAINTAINER_MODE.
  193. $seen_maint_mode = 0;
  194.  
  195. # TRUE if we've seen PACKAGE and VERSION.
  196. $seen_package = 0;
  197. $seen_version = 0;
  198.  
  199. # Actual version we've seen.
  200. $package_version = '';
  201.  
  202. # Line number where we saw version definition.
  203. $package_version_line = 0;
  204.  
  205. # TRUE if we've seen AM_PATH_LISPDIR.
  206. $seen_lispdir = 0;
  207.  
  208. # TRUE if we've seen AC_EXEEXT.
  209. $seen_exeext = 0;
  210.  
  211. # TRUE if we've seen AC_OBJEXT.
  212. $seen_objext = 0;
  213.  
  214. # TRUE if we've seen AC_ENABLE_MULTILIB.
  215. $seen_multilib = 0;
  216.  
  217. # Hash table of discovered configure substitutions.  Keys are names,
  218. # values are `FILE:LINE' strings which are used by error message
  219. # generation.
  220. %configure_vars = ();
  221.  
  222. # This is used to keep track of which variable definitions we are
  223. # scanning.  It is only used in certain limited ways, but it has to be
  224. # global.  It is declared just for documentation purposes.
  225. %vars_scanned = ();
  226.  
  227. # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
  228. # handled in a funny way: if seen in the top-level Makefile.am, it is
  229. # used for every directory which does not specify a different value.
  230. # The rationale here is that some directories (eg gettext) might be
  231. # distributions of other packages, and thus require their own charset
  232. # info.  However, the DIST_CHARSET must be the same for the entire
  233. # package; it can only be set at top-level.
  234. # FIXME: this yields bugs when rebuilding.  What to do?  Always
  235. # read (and sometimes discard) top-level Makefile.am?
  236. $maint_charset = '';
  237. $dist_charset = 'utf8';        # recode doesn't support this yet.
  238.  
  239. # Name of input file ("Makefile.in") and output file ("Makefile.am").
  240. # These have no directory components.
  241. $am_file_name = '';
  242. $in_file_name = '';
  243.  
  244. # TRUE if --cygnus seen.
  245. $cygnus_mode = 0;
  246.  
  247. # Keys of this hash are names of dependency files to ignore.
  248. %omit_dependencies = ();
  249.  
  250. # Hash table of AM_CONDITIONAL variables seen in configure.
  251. %configure_cond = ();
  252.  
  253. # Map from obsolete macros to hints for new macros.
  254. # FIXME complete the list so that there are no `0' hints.
  255. %obsolete_macros =
  256.     (
  257.      'AC_FEATURE_CTYPE', "use \`AC_HEADER_STDC'",
  258.      'AC_FEATURE_ERRNO', "add \`strerror' to \`AC_REPLACE_FUNCS(...)'",
  259.      'AC_FEATURE_EXIT', 0,
  260.      'AC_SYSTEM_HEADER', 0,
  261.  
  262.      # Note that we do not handle this one, because it is still run
  263.      # from AM_CONFIG_HEADER.  So we deal with it specially in
  264.      # scan_configure.
  265.      # 'AC_CONFIG_HEADER', "use \`AM_CONFIG_HEADER'",
  266.  
  267.      'fp_C_PROTOTYPES', "use \`AM_C_PROTOTYPES'",
  268.      'fp_PROG_CC_STDC', "use \`AM_PROG_CC_STDC'",
  269.      'fp_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
  270.      'fp_WITH_DMALLOC', "use \`AM_WITH_DMALLOC'",
  271.      'fp_WITH_REGEX', "use \`AM_WITH_REGEX'",
  272.      'gm_PROG_LIBTOOL', "use \`AM_PROG_LIBTOOL'",
  273.      'jm_MAINTAINER_MODE', "use \`AM_MAINTAINER_MODE'",
  274.      'md_TYPE_PTRDIFF_T', "use \`AM_TYPE_PTRDIFF_T'",
  275.      'ud_PATH_LISPDIR', "use \`AM_PATH_LISPDIR'",
  276.  
  277.      # Now part of autoconf proper, under a different name.
  278.      'AM_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
  279.      'fp_FUNC_FNMATCH', "use \`AC_FUNC_FNMATCH'",
  280.      'AM_SANITY_CHECK_CC', "automatically done by \`AC_PROG_CC'",
  281.      'AM_PROG_INSTALL', "use \`AC_PROG_INSTALL'",
  282.      'AM_EXEEEXT', "use \`AC_EXEEXT'",
  283.      'AM_CYGWIN32', "use \`AC_CYGWIN32'",
  284.      'AM_MINGW32', "use \`AC_MINGW32'",
  285.  
  286. # These aren't quite obsolete.
  287. #      'md_PATH_PROG',
  288.      );
  289.  
  290. # Regexp to match the above macros.
  291. $obsolete_rx = '(' . join ('|', keys %obsolete_macros) . ')';
  292.  
  293. # This maps extensions onto language names.
  294. %extension_map = ();
  295.  
  296. # This maps languages names onto properties.
  297. %language_map = ();
  298.  
  299.  
  300.  
  301. # Initialize global constants and our list of languages that are
  302. # internally supported.
  303. &initialize_global_constants;
  304.  
  305. ®ister_language ('c', '', 1,
  306.             'c');
  307. ®ister_language ('cxx', 'CXXLINK', 0,
  308.             'c++', 'cc', 'cpp', 'cxx', 'C');
  309. ®ister_language ('objc', 'OBJCLINK', 0,
  310.                     'm');
  311. ®ister_language ('header', '', 0,
  312.             'h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc');
  313. ®ister_language ('yacc', '', 1,
  314.             'y');
  315. ®ister_language ('yaccxx', 'CXXLINK', 0,
  316.             'y++', 'yy', 'yxx');
  317. ®ister_language ('lex', '', 1,
  318.             'l');
  319. ®ister_language ('lexxx', 'CXXLINK', 0,
  320.             'l++', 'll', 'lxx');
  321. ®ister_language ('asm', '', 0,
  322.             's', 'S');
  323. ®ister_language ('f77', 'F77LINK', 0,
  324.             'f', 'for', 'f90');
  325. ®ister_language ('ppf77', 'F77LINK', 0,
  326.             'F');
  327. ®ister_language ('ratfor', 'F77LINK', 0,
  328.             'r');
  329.  
  330.  
  331. # Parse command line.
  332. &parse_arguments (@ARGV);
  333.  
  334. # Do configure.in scan only once.
  335. &scan_configure;
  336.  
  337. die "automake: no \`Makefile.am' found or specified\n"
  338.     if ! @input_files;
  339.  
  340. # If --generate-deps was given, we don't do anything else
  341. #
  342. if ($generate_deps)
  343. {
  344.     die "automake: Must specify --include-deps (or -i) when generating\n"
  345.     if $use_dependencies;
  346.     die "automake: Must provide --build-dir when generating\n"
  347.     if ! $build_directory;
  348.     die "automake: Must provide --srcdir-name when generating\n"
  349.     if ! $srcdir_name;
  350.  
  351.     open (GDEP, ">$output_directory/.dep_segment")
  352.     || die "automake: Could not open `$output_directory/.dep_segment': $!\n";
  353.  
  354.     &handle_dependencies;
  355.     print GDEP $output_rules;
  356.  
  357.     close(GDEP);
  358.     exit $exit_status;
  359. }
  360.  
  361. # Now do all the work on each file.
  362. foreach $am_file (@input_files)
  363. {
  364.     if (! -f ($am_file . '.am'))
  365.     {
  366.     &am_error ("\`" . $am_file . ".am' does not exist");
  367.     }
  368.     else
  369.     {
  370.      &generate_makefile ($output_files{$am_file}, $am_file);
  371.     }
  372. }
  373.  
  374. &am_conf_error ("AC_PROG_INSTALL must be used in configure.in")
  375.     if (! $seen_prog_install);
  376.  
  377. exit $exit_status;
  378.  
  379.  
  380. ################################################################
  381.  
  382. # Parse command line.
  383. sub parse_arguments
  384. {
  385.     local (@arglist) = @_;
  386.  
  387.     # Start off as gnu.
  388.     &set_strictness ('gnu');
  389.  
  390.     while (@arglist)
  391.     {
  392.     if ($arglist[0] eq "--version")
  393.     {
  394.         print "automake (GNU $PACKAGE) $VERSION\n\n";
  395.         print "Copyright (C) 1999 Free Software Foundation, Inc.\n";
  396.         print "This is free software; see the source for copying conditions.  There is NO\n";
  397.         print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
  398.         print "Written by Tom Tromey <tromey\@cygnus.com>\n";
  399.  
  400.         exit 0;
  401.     }
  402.     elsif ($arglist[0] eq "--help")
  403.     {
  404.         &usage;
  405.     }
  406.     elsif ($arglist[0] =~ /^--amdir=(.+)$/)
  407.     {
  408.         $am_dir = $1;
  409.     }
  410.     elsif ($arglist[0] eq '--amdir')
  411.     {
  412.         &require_argument (@arglist);
  413.         shift (@arglist);
  414.         $am_dir = $arglist[0];
  415.     }
  416.     elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
  417.     {
  418.         # Must end in /.
  419.         $build_directory = $1 . '/';
  420.     }
  421.     elsif ($arglist[0] eq '--build-dir')
  422.     {
  423.         &require_argument (@arglist);
  424.         shift (@arglist);
  425.         # Must end in /.
  426.         $build_directory = $arglist[0] . '/';
  427.     }
  428.     elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
  429.     {
  430.         $srcdir_name = $1;
  431.     }
  432.     elsif ($arglist[0] eq '--srcdir-name')
  433.     {
  434.         &require_argument (@arglist);
  435.         shift (@arglist);
  436.         $srcdir_name = $arglist[0];
  437.     }
  438.     elsif ($arglist[0] eq '--gnu')
  439.     {
  440.         &set_strictness ('gnu');
  441.     }
  442.     elsif ($arglist[0] eq '--gnits')
  443.     {
  444.         &set_strictness ('gnits');
  445.     }
  446.     elsif ($arglist[0] eq '--cygnus')
  447.     {
  448.         $cygnus_mode = 1;
  449.     }
  450.     elsif ($arglist[0] eq '--foreign')
  451.     {
  452.         &set_strictness ('foreign');
  453.     }
  454.     elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
  455.     {
  456.         $cmdline_use_dependencies = 0;
  457.     }
  458.     elsif ($arglist[0] eq '--generate-deps')
  459.     {
  460.         $generate_deps = 1;
  461.     }
  462.     elsif ($arglist[0] eq '--no-force')
  463.     {
  464.         $force_generation = 0;
  465.     }
  466.     elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
  467.     {
  468.         # Set output directory.
  469.         $output_directory = $1;
  470.     }
  471.     elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
  472.     {
  473.         &require_argument (@arglist);
  474.         shift (@arglist);
  475.         $output_directory = $arglist[0];
  476.     }
  477.     elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
  478.     {
  479.         $add_missing = 1;
  480.     }
  481.     elsif ($arglist[0] eq '--copy' || $arglist[0] eq '-c')
  482.     {
  483.         $copy_missing = 1;
  484.     }
  485.     elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
  486.     {
  487.         $verbose = 1;
  488.     }
  489.     elsif ($arglist[0] eq '--')
  490.     {
  491.         # Stop option processing.
  492.         shift (@arglist);
  493.         push (@input_files, @arglist);
  494.         last;
  495.     }
  496.     elsif ($arglist[0] =~ /^-/)
  497.     {
  498.         die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
  499.     }
  500.     else
  501.     {
  502.         # Handle $local:$input syntax.  Note that we only examine
  503.         # the first ":" file to see if it is automake input; the
  504.         # rest are just taken verbatim.  We still keep all the
  505.         # files around for dependency checking, however.
  506.         local ($local, $input, @rest) = split (/:/, $arglist[0]);
  507.         if (! $input)
  508.         {
  509.         $input = $local;
  510.         }
  511.         else
  512.         {
  513.         # Strip .in; later on .am is tacked on.  That is how
  514.         # the automake input file is found.  Maybe not the
  515.         # best way, but it is easy to explain.  FIXME: should
  516.         # be error if .in is missing.
  517.         $input =~ s/\.in$//;
  518.         }
  519.         push (@input_files, $input);
  520.         $output_files{$input} = join (':', ($local, @rest));
  521.     }
  522.  
  523.     shift (@arglist);
  524.     }
  525.  
  526.     # Take global strictness from whatever we currently have set.
  527.     $default_strictness = $strictness;
  528.     $default_strictness_name = $strictness_name;
  529. }
  530.  
  531. # Ensure argument exists, or die.
  532. sub require_argument
  533. {
  534.     local ($arg, @arglist) = @_;
  535.     die "automake: no argument given for option \`$arg'\n"
  536.     if ! @arglist;
  537. }
  538.  
  539. ################################################################
  540.  
  541. # Generate a Makefile.in given the name of the corresponding Makefile and
  542. # the name of the file output by config.status.
  543. sub generate_makefile
  544. {
  545.     local ($output, $makefile) = @_;
  546.  
  547.     ($am_file_name = $makefile) =~ s/^.*\///;
  548.     $in_file_name = $am_file_name . '.in';
  549.     $am_file_name .= '.am';
  550.  
  551.     # $OUTPUT is encoded.  If it contains a ":" then the first element
  552.     # is the real output file, and all remaining elements are input
  553.     # files.  We don't scan or otherwise deal with these input file,
  554.     # other than to mark them as dependencies.  See scan_configure for
  555.     # details.
  556.     local (@secondary_inputs);
  557.     ($output, @secondary_inputs) = split (/:/, $output);
  558.  
  559.     &initialize_per_input;
  560.     $relative_dir = &dirname ($output);
  561.     $am_relative_dir = &dirname ($makefile);
  562.  
  563.     # At the toplevel directory, we might need config.guess, config.sub
  564.     # or libtool scripts (ltconfig and ltmain.sh).
  565.     if ($relative_dir eq '.')
  566.     {
  567.      # libtool requires some files.
  568.      &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
  569.                         @libtoolize_files)
  570.         if $seen_libtool;
  571.  
  572.         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
  573.         # config.sub.
  574.         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
  575.         if $seen_canonical;
  576.     }
  577.  
  578.     # We still need Makefile.in here, because sometimes the `dist'
  579.     # target doesn't re-run automake.
  580.     if ($am_relative_dir eq $relative_dir)
  581.     {
  582.     # Only distribute the files if they are in the same subdir as
  583.     # the generated makefile.
  584.     &push_dist_common ($in_file_name, $am_file_name);
  585.     }
  586.     push (@sources, '$(SOURCES)')
  587.     if &variable_defined ('SOURCES');
  588.     push (@objects, '$(OBJECTS)')
  589.     if &variable_defined ('OBJECTS');
  590.  
  591.     &read_main_am_file ($makefile . '.am');
  592.     if (&handle_options)
  593.     {
  594.     # Fatal error.  Just return, so we can continue with next file.
  595.     return;
  596.     }
  597.  
  598.     # Check first, because we might modify some state.
  599.     &check_cygnus;
  600.     &check_gnu_standards;
  601.     &check_gnits_standards;
  602.  
  603.     &handle_configure ($output, $makefile, @secondary_inputs);
  604.     &handle_gettext;
  605.     &handle_libraries;
  606.     &handle_ltlibraries;
  607.     &handle_programs;
  608.     &handle_scripts;
  609.  
  610.     &handle_built_sources;
  611.  
  612.     # This must be run after all the sources are scanned.
  613.     &finish_languages;
  614.  
  615.     # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
  616.     # on this (but currently does).
  617.     $contents{'SOURCES'} = join (' ', @sources);
  618.     $contents{'OBJECTS'} = join (' ', @objects);
  619.  
  620.     &handle_multilib;
  621.     &handle_texinfo;
  622.     &handle_emacs_lisp;
  623.     &handle_java;
  624.     &handle_man_pages;
  625.     &handle_data;
  626.     &handle_headers;
  627.     &handle_subdirs;
  628.     &handle_tags;
  629.     &handle_minor_options;
  630.     &handle_dist ($makefile);
  631.     &handle_dependencies;
  632.     &handle_tests;
  633.     &handle_footer;
  634.     &handle_merge_targets ($output);
  635.     &handle_installdirs;
  636.     &handle_clean;
  637.     &handle_phony;
  638.  
  639.     &check_typos;
  640.  
  641.     if (! -d ($output_directory . '/' . $am_relative_dir))
  642.     {
  643.     mkdir ($output_directory . '/' . $am_relative_dir, 0755);
  644.     }
  645.  
  646.     local ($out_file) = $output_directory . '/' . $makefile . ".in";
  647.     if (! $force_generation && -e $out_file)
  648.     {
  649.     local ($am_time) = (stat ($makefile . '.am'))[9];
  650.     local ($in_time) = (stat ($out_file))[9];
  651.     # FIXME: should cache these times.
  652.     local ($conf_time) = (stat ('configure.in'))[9];
  653.     # FIXME: how to do unsigned comparison?
  654.     if ($am_time < $in_time || $am_time < $conf_time)
  655.     {
  656.         # No need to update.
  657.         return;
  658.     }
  659.     if (-f 'aclocal.m4')
  660.     {
  661.         local ($acl_time) = (stat _)[9];
  662.         return if ($am_time < $acl_time);
  663.     }
  664.     }
  665.  
  666.     if (! open (GM_FILE, "> " . $out_file))
  667.     {
  668.     warn "automake: ${am_file}.in: cannot write: $!\n";
  669.     $exit_status = 1;
  670.     return;
  671.     }
  672.     print "automake: creating ", $makefile, ".in\n" if $verbose;
  673.  
  674.     print GM_FILE $output_vars;
  675.     # We make sure that `all:' is the first target.
  676.     print GM_FILE $output_all;
  677.     print GM_FILE $output_header;
  678.     print GM_FILE $output_rules;
  679.     print GM_FILE $output_trailer;
  680.  
  681.     close (GM_FILE);
  682. }
  683.  
  684. ################################################################
  685.  
  686. # Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
  687. sub handle_options
  688. {
  689.     if (&variable_defined ('AUTOMAKE_OPTIONS'))
  690.     {
  691.     foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
  692.     {
  693.         $options{$_} = 1;
  694.         if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
  695.         {
  696.         &set_strictness ($_);
  697.         }
  698.         elsif ($_ eq 'cygnus')
  699.         {
  700.         $cygnus_mode = 1;
  701.         }
  702.         elsif (/ansi2knr/)
  703.         {
  704.         # An option like "../lib/ansi2knr" is allowed.  With
  705.         # no path prefix, we assume the required programs are
  706.         # in this directory.  We save the actual option for
  707.         # later.
  708.         $options{'ansi2knr'} = $_;
  709.         }
  710.         elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
  711.            || $_ eq 'dist-shar' || $_ eq 'dist-zip'
  712.            || $_ eq 'dist-tarZ' || $_ eq 'dejagnu'
  713.            || $_ eq 'no-texinfo.tex'
  714.            || $_ eq 'readme-alpha' || $_ eq 'check-news')
  715.         {
  716.         # Explicitly recognize these.
  717.         }
  718.         elsif ($_ eq 'no-dependencies')
  719.         {
  720.         $use_dependencies = 0;
  721.         }
  722.         elsif (/([0-9]+)\.([0-9]+)([a-z])?/)
  723.         {
  724.         # Got a version number.
  725.  
  726.         local ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
  727.  
  728.         if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
  729.         {
  730.             print STDERR
  731.             "automake: programming error: version is incorrect\n";
  732.             exit 1;
  733.         }
  734.         local ($tmajor, $tminor, $talpha) = ($1, $2, $3);
  735.  
  736.         # 2.0 is better than 1.0.
  737.         # 1.2 is better than 1.1.
  738.         # 1.2a is better than 1.2.
  739.         if ($rmajor > $tmajor
  740.             || ($rmajor == $tmajor && $rminor > $tminor)
  741.             || ($rminor == $tminor && $rminor == $tminor
  742.             && $ralpha gt $talpha))
  743.         {
  744.             &am_line_error ('AUTOMAKE_OPTIONS',
  745.                     "require version $_, only have $VERSION");
  746.             return 1;
  747.         }
  748.         }
  749.         else
  750.         {
  751.         &am_line_error ('AUTOMAKE_OPTIONS',
  752.                 "option \`" . $_ . "\' not recognized");
  753.         }
  754.     }
  755.     }
  756.  
  757.     if ($strictness == $GNITS)
  758.     {
  759.     $options{'readme-alpha'} = 1;
  760.     $options{'check-news'} = 1;
  761.     }
  762.  
  763.     return 0;
  764. }
  765.  
  766. # Return object extension.  Just once, put some code into the output.
  767. # Argument is the name of the output file
  768. sub get_object_extension
  769. {
  770.     local ($out) = @_;
  771.  
  772.     # Maybe require libtool library object files.
  773.     local ($extension) = '.o';
  774.     $extension = '.$(OBJEXT)' if $seen_objext;
  775.     $extension = '.lo' if ($out =~ /\.la$/);
  776.  
  777.     if (! $included_generic_compile)
  778.     {
  779.     # Boilerplate.
  780.     local ($xform) = '';
  781.     if (&variable_defined ('CONFIG_HEADER'))
  782.     {
  783.         local ($one_hdr);
  784.         foreach $one_hdr (split (' ', &variable_value ('CONFIG_HEADER')))
  785.         {
  786.         local ($var);
  787.         ($var = &dirname ($one_hdr)) =~ s/(\W)/\\$1/g;
  788.         $xform .= ' ' if $xform;
  789.         $xform .= '-I' . $var;
  790.         }
  791.     }
  792.     $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go;';
  793.     $output_vars .= &file_contents_with_transform ($xform,
  794.                                'comp-vars');
  795.  
  796.     $xform = (($use_dependencies
  797.            ? 's/^NOTDEPEND.*$//;'
  798.            : 's/^NOTDEPEND//;')
  799.           . ($seen_objext ? 's/^OBJEXT//;' : 's/^OBJEXT.*$//;'));
  800.     $output_rules .= &file_contents_with_transform ($xform, 'compile');
  801.  
  802.     &push_phony_cleaners ('compile');
  803.  
  804.     # If using X, include some extra variable definitions.  NOTE
  805.     # we don't want to force these into CFLAGS or anything,
  806.     # because not all programs will necessarily use X.
  807.     if ($seen_path_xtra)
  808.     {
  809.         local ($var);
  810.         foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
  811.         {
  812.         &define_configure_variable ($var);
  813.         }
  814.     }
  815.  
  816.     push (@suffixes, '.c', '.o', '.S', '.s');
  817.     push (@suffixes, '.obj') if $seen_objext;
  818.     push (@clean, 'compile');
  819.  
  820.     $included_generic_compile = 1;
  821.     }
  822.  
  823.     if ($seen_libtool && ! $included_libtool_compile)
  824.     {
  825.     # Output the libtool compilation rules.
  826.     $output_rules .=
  827.         &file_contents_with_transform
  828.         ($use_dependencies ? 's/^NOTDEPEND.*$//;' : 's/^NOTDEPEND//;',
  829.          'libtool');
  830.  
  831.     &push_phony_cleaners ('libtool');
  832.  
  833.     push (@suffixes, '.lo');
  834.     push (@clean, 'libtool');
  835.  
  836.     $included_libtool_compile = 1;
  837.     }
  838.  
  839.     # Check for automatic de-ANSI-fication.
  840.     if (defined $options{'ansi2knr'})
  841.     {
  842.     $extension = '$U' . $extension;
  843.     if (! $included_knr_compile)
  844.     {
  845.         if (! $am_c_prototypes)
  846.         {
  847.         &am_line_error ('AUTOMAKE_OPTIONS',
  848.                 "option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
  849.         &keyed_aclocal_warning ('AM_C_PROTOTYPES');
  850.         # Only give this error once.
  851.         $am_c_prototypes = 1;
  852.         }
  853.  
  854.         # Only require ansi2knr files if they should appear in
  855.         # this directory.
  856.         if ($options{'ansi2knr'} eq 'ansi2knr')
  857.         {
  858.         &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
  859.                      'ansi2knr.c', 'ansi2knr.1');
  860.         $output_rules .= &file_contents ('kr-extra');
  861.         push (@clean, 'krextra');
  862.         &push_phony_cleaners ('krextra');
  863.         }
  864.  
  865.         # Generate rules to build ansi2knr.  If it is in some
  866.         # other directory, then generate dependencies but have the
  867.         # rule just run elsewhere.
  868.         $objext = $seen_objext ? ".$(OBJEXT)" : ".o";
  869.         $output_rules .= ($options{'ansi2knr'} . ': '
  870.                   . $options{'ansi2knr'} . $objext . "\n");
  871.         if ($options{'ansi2knr'} eq 'ansi2knr')
  872.         {
  873.         $output_rules .= ("\t\$(LINK) ansi2knr" . $objext
  874.                   . " \$(LIBS)\n"
  875.                   . "ansi2knr" . $objext
  876.                   . ": \$(CONFIG_HEADER)\n\n");
  877.         }
  878.         else
  879.         {
  880.         $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
  881.                   . " && \$(MAKE) \$(AM_MAKEFLAGS) "
  882.                   . "ansi2knr\n\n");
  883.         # This is required for non-GNU makes.
  884.             $output_rules .= ($options{'ansi2knr'} . $objext . ":\n");
  885.         $output_rules .= ("\tcd " . &dirname ($options{'ansi2knr'})
  886.                   . " && \$(MAKE) \$(AM_MAKEFLAGS)"
  887.                   . " ansi2knr" . $objext . "\n\n");
  888.         }
  889.  
  890.         # Make sure ansi2knr can be found: if no path specified,
  891.         # specify "./".
  892.         if ($options{'ansi2knr'} eq 'ansi2knr')
  893.         {
  894.         # Substitution from AM_C_PROTOTYPES.  This makes it be
  895.         # built only when necessary.
  896.         &define_configure_variable ('ANSI2KNR');
  897.         # ansi2knr needs to be built before subdirs, so unshift it.
  898.         unshift (@all, '$(ANSI2KNR)');
  899.         }
  900.         else
  901.         {
  902.         # Found in another directory.
  903.         &define_variable ("ANSI2KNR", $options{'ansi2knr'});
  904.         }
  905.  
  906.         $output_rules .= &file_contents ('clean-kr');
  907.  
  908.         push (@clean, 'kr');
  909.         &push_phony_cleaners ('kr');
  910.  
  911.         $included_knr_compile = 1;
  912.     }
  913.     }
  914.  
  915.     return $extension;
  916. }
  917.  
  918. # Call finish function for each language that was used.
  919. sub finish_languages
  920. {
  921.     local ($ext, $name, $lang, %done);
  922.     local ($non_c) = 1;
  923.     foreach $ext (sort keys %extension_seen)
  924.     {
  925.     $lang = $extension_map{$ext};
  926.     next if defined $done{$lang};
  927.     $done{$lang} = 1;
  928.     $non_c = 0 if $lang !~ /(objc|cxx|f77|ratfor)$/;
  929.  
  930.     # Compute the function name of the finisher and then call it.
  931.     $name = 'lang_' . $lang . '_finish';
  932.     do $name ();
  933.     }
  934.  
  935.     # If the project is entirely C++ or entirely Fortran 77, don't
  936.     # bother with the C stuff.  But if anything else creeps in, then use
  937.     # it.
  938.     if (! $non_c || scalar keys %suffix_rules > 0)
  939.     {
  940.     local ($ltcompile, $ltlink) = &libtool_compiler;
  941.  
  942.     &define_configure_variable ('CFLAGS');
  943.     &define_variable ('COMPILE',
  944.               '$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)');
  945.     &define_variable ('LTCOMPILE',
  946.               $ltcompile .
  947.               '$(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)')
  948.         if ($seen_libtool);
  949.     &define_variable ('CCLD', '$(CC)');
  950.     &define_variable ('LINK', $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@');
  951.     }
  952. }
  953.  
  954. # Output a rule to build from a YACC source.  The output from YACC is
  955. # compiled with C or C++, depending on the extension of the YACC file.
  956. sub output_yacc_build_rule
  957. {
  958.     local ($yacc_suffix, $use_ylwrap, $c_suffix) = @_;
  959.  
  960.     local ($suffix);
  961.     ($suffix = $yacc_suffix) =~ tr/y/c/;
  962.     push (@suffixes, $yacc_suffix, $suffix);
  963.  
  964.     # Generate rule for c/c++.
  965.     $output_rules .= "$yacc_suffix$suffix:\n\t";
  966.  
  967.     if ($use_ylwrap)
  968.     {
  969.     $output_rules .= ('$(SHELL) $(YLWRAP)'
  970.               . ' "$(YACC)" $< y.tab.c $*' . $suffix
  971.               . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)');
  972.     }
  973.     else
  974.     {
  975.     $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*'
  976.               . $suffix . "\n"
  977.               . "\tif test -f y.tab.h; then \\\n"
  978.               . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n"
  979.               . "\telse :; fi");
  980.     }
  981.     $output_rules .= "\n";
  982. }
  983.  
  984. sub output_lex_build_rule
  985. {
  986.     local ($lex_suffix, $use_ylwrap) = @_;
  987.     local ($c_suffix);
  988.  
  989.     ($c_suffix = $lex_suffix) =~ tr/l/c/;
  990.     push (@suffixes, $lex_suffix);
  991.     &define_configure_variable ('LEX_OUTPUT_ROOT');
  992.     &define_configure_variable ('LEXLIB');
  993.     $output_rules .= "$lex_suffix$c_suffix:\n\t";
  994.  
  995.     if ($use_ylwrap)
  996.     {
  997.         # Is the $@ correct here?  If so, why not use it in the ylwrap
  998.         # build rule for yacc above?
  999.     $output_rules .= '$(SHELL) $(YLWRAP)'
  1000.         . ' "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS)';
  1001.     }
  1002.     else
  1003.     {
  1004.     $output_rules .= '$(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
  1005.     }
  1006.     $output_rules .= "\n";
  1007. }
  1008.  
  1009.  
  1010. # Check to make sure a source defined in LIBOBJS is not explicitly
  1011. # mentioned.  This is a separate function (as opposed to being inlined
  1012. # in handle_source_transform) because it isn't always appropriate to
  1013. # do this check.
  1014. sub check_libobjs_sources
  1015. {
  1016.     local ($one_file, $unxformed) = @_;
  1017.  
  1018.     local ($prefix, $file, @files);
  1019.     foreach $prefix ('', 'EXTRA_')
  1020.     {
  1021.     if (&variable_defined ($prefix . $one_file . '_SOURCES'))
  1022.     {
  1023.         @files = &variable_value_as_list (($prefix
  1024.                            . $one_file . '_SOURCES'),
  1025.                           'all');
  1026.     }
  1027.     elsif ($prefix eq '')
  1028.     {
  1029.         @files = ($unxformed . '.c');
  1030.     }
  1031.     else
  1032.     {
  1033.         next;
  1034.     }
  1035.  
  1036.     foreach $file (@files)
  1037.     {
  1038.         if (defined $libsources{$file})
  1039.         {
  1040.         &am_line_error ($prefix . $one_file . '_SOURCES',
  1041.                 "automatically discovered file \`$file' should not be explicitly mentioned");
  1042.         }
  1043.     }
  1044.     }
  1045. }
  1046.  
  1047. # Does much of the actual work for handle_source_transform.
  1048. # Arguments are:
  1049. #   object extension (e.g., `$U.lo')
  1050. #   list of source files to transform
  1051. # Result is a list
  1052. #   first element is name of linker to use (empty string for default linker)
  1053. #   remaining elements are names of objects
  1054. sub handle_single_transform_list
  1055. {
  1056.     local ($obj, @files) = @_;
  1057.     local (@result) = ();
  1058.     local ($nonansi_obj) = $obj;
  1059.     $nonansi_obj =~ s/_//g;
  1060.     local (%linkers_used) = ();
  1061.     if (@files > 0)
  1062.     {
  1063.     # Turn sources into objects.
  1064.     foreach (@files)
  1065.     {
  1066.         # Skip things that look like configure substitutions.
  1067.         next if /^\@.*\@$/;
  1068.  
  1069.         # We don't support source files in a subdirectory.  The
  1070.         # reason is that we'd want to put the .o into a similar
  1071.         # subdirectory, but this means finding a good way to make
  1072.         # the directory.  Later.
  1073.         if (/\//)
  1074.         {
  1075.         &am_error
  1076.             ("not supported: source file `$_' is in subdirectory");
  1077.         next;
  1078.         }
  1079.  
  1080.         # Split file name into base and extension.
  1081.         local ($base, $extension, $linker, $object);
  1082.         next if ! /^(.*)\.(.*)$/;
  1083.         $base = $1;
  1084.         $extension = $2;
  1085.  
  1086.         local ($lang) = $extension_map{$extension};
  1087.         if ($lang)
  1088.         {
  1089.         &saw_extension ($extension);
  1090.         # Found the language, so see what it says.
  1091.         local ($subr) = 'lang_' . $lang . '_rewrite';
  1092.         # Note: computed subr call.
  1093.         local ($r) = do $subr ($base, $extension);
  1094.         # Skip this entry if we were asked not to process it.
  1095.         next if ! $r;
  1096.  
  1097.         # Now extract linker and other info.
  1098.         $linker = $language_map{$lang . '-linker'};
  1099.  
  1100.         if ($language_map{$lang . '-ansi-p'})
  1101.         {
  1102.             $object = $base . $obj;
  1103.         }
  1104.         else
  1105.         {
  1106.             $object = $base . $nonansi_obj;
  1107.         }
  1108.         }
  1109.          elsif ($extension =~ /^$source_suffix_pattern$/) 
  1110.          {
  1111.         # We just rewrite it.  Maybe we should do more.
  1112.         $object = $base . '.' . $suffix_rules{$extension};
  1113.         $linker = '';
  1114.          }
  1115.         else
  1116.         {
  1117.         # No error message here.  Used to have one, but it was
  1118.         # very unpopular.
  1119.         next;
  1120.         }
  1121.  
  1122.         $linkers_used{$linker} = 1;
  1123.  
  1124.         push (@result, $object);
  1125.  
  1126.         # Transform .o or $o file into .P file (for automatic
  1127.         # dependency code).
  1128.         $dep_files{'.deps/' . $base . '.P'} = 1;
  1129.     }
  1130.     }
  1131.  
  1132.     return (&resolve_linker (%linkers_used), @result);
  1133. }
  1134.  
  1135. # Handle SOURCE->OBJECT transform for one program or library.
  1136. # Arguments are:
  1137. #   canonical (transformed) name of object to build
  1138. #   actual name of object to build
  1139. #   object extension (ie either `.o' or `$o'.
  1140. # Return result is name of linker variable that must be used.
  1141. # Empty return means just use `LINK'.
  1142. sub handle_source_transform
  1143. {
  1144.     # one_file is canonical name.  unxformed is given name.  obj is
  1145.     # object extension.
  1146.     local ($one_file, $unxformed, $obj) = @_;
  1147.  
  1148.     local ($linker) = '';
  1149.  
  1150.     if (&variable_defined ($one_file . "_OBJECTS"))
  1151.     {
  1152.     &am_line_error ($one_file . '_OBJECTS',
  1153.             $one_file . '_OBJECTS', 'should not be defined');
  1154.     # No point in continuing.
  1155.     return;
  1156.     }
  1157.  
  1158.     local (@files, @result, $prefix, $temp);
  1159.     foreach $prefix ('', 'EXTRA_')
  1160.     {
  1161.     @files = ();
  1162.     local ($var) = $prefix . $one_file . "_SOURCES";
  1163.     if (&variable_defined ($var))
  1164.     {
  1165.         push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
  1166.         push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
  1167.         unless $prefix eq 'EXTRA_';
  1168.         local (@conds) = &variable_conditions ($var);
  1169.         if (! @conds)
  1170.         {
  1171.         @files = &variable_value_as_list ($var, '');
  1172.         }
  1173.         else
  1174.         {
  1175.         local ($cond);
  1176.         foreach $cond (@conds)
  1177.         {
  1178.             @files = &variable_value_as_list ($var, $cond);
  1179.             ($temp, @result) = &handle_single_transform_list ($obj,
  1180.                                       @files);
  1181.             $linker = $temp if $linker eq '';
  1182.  
  1183.             # Define _OBJECTS conditionally.
  1184.             &define_pretty_variable ($one_file . '_OBJECTS', $cond,
  1185.                          @result)
  1186.             unless $prefix eq 'EXTRA_';
  1187.         }
  1188.  
  1189.         next;
  1190.         }
  1191.     }
  1192.     elsif ($prefix eq '')
  1193.     {
  1194.         &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
  1195.         push (@sources, $unxformed . '.c');
  1196.         push (@objects, $unxformed . $obj);
  1197.         push (@files, $unxformed . '.c');
  1198.     }
  1199.  
  1200.     ($temp, @result) = &handle_single_transform_list ($obj, @files);
  1201.     $linker = $temp if $linker eq '';
  1202.     &define_pretty_variable ($one_file . "_OBJECTS", '', @result)
  1203.         unless $prefix eq 'EXTRA_';
  1204.     }
  1205.  
  1206.     return $linker;
  1207. }
  1208.  
  1209. # Handle the BUILT_SOURCES variable.
  1210. sub handle_built_sources
  1211. {
  1212.     return unless &variable_defined ('BUILT_SOURCES');
  1213.  
  1214.     local (@sources) = &variable_value_as_list ('BUILT_SOURCES', 'all');
  1215.     local ($s);
  1216.     foreach $s (@sources)
  1217.     {
  1218.     if (/^\@.*\@$/)
  1219.     {
  1220.         # FIXME: is this really the right thing to do?
  1221.         &am_line_error ('BUILT_SOURCES',
  1222.                 "\`BUILT_SOURCES' should not contain a configure substitution");
  1223.         last;
  1224.     }
  1225.     }
  1226.  
  1227.     # We don't care about the return value of this function.  We just
  1228.     # want to make sure to update %dep_files with the contents of
  1229.     # BUILT_SOURCES.
  1230.     &handle_single_transform_list (".o", @sources);
  1231. }
  1232.  
  1233. # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
  1234. # Also, generate _DEPENDENCIES variable if appropriate.
  1235. # Arguments are:
  1236. #   transformed name of object being built, or empty string if no object
  1237. #   name of _LDADD/_LIBADD-type variable to examine
  1238. #   boolean (lex_seen) which is true if a lex source file was seen in this
  1239. #     object.  valid only for LDADDs, not LIBADDs.
  1240. # Returns 1 if LIBOBJS seen, 0 otherwise.
  1241. sub handle_lib_objects
  1242. {
  1243.     local ($xname, $var, $lex_seen) = @_;
  1244.     local ($ret);
  1245.  
  1246.     die "automake: programming error 1 in handle_lib_objects\n"
  1247.     if ! &variable_defined ($var);
  1248.  
  1249.     die "automake: programming error 2 in handle_lib_objects\n"
  1250.     if $lex_seen && $var =~ /LIBADD/;
  1251.  
  1252.     local (@conds) = &variable_conditions ($var);
  1253.     if (! @conds)
  1254.     {
  1255.     $ret = &handle_lib_objects_cond ($xname, $var, $lex_seen, '');
  1256.     }
  1257.     else
  1258.     {
  1259.     local ($cond);
  1260.     $ret = 0;
  1261.     foreach $cond (@conds)
  1262.     {
  1263.         if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
  1264.         {
  1265.         $ret = 1;
  1266.         }
  1267.     }
  1268.     }
  1269.  
  1270.     return $ret;
  1271. }
  1272.  
  1273. # Subroutine of handle_lib_objects: handle a particular condition.
  1274. sub handle_lib_objects_cond
  1275. {
  1276.     local ($xname, $var, $lex_seen, $cond) = @_;
  1277.  
  1278.     # We recognize certain things that are commonly put in LIBADD or
  1279.     # LDADD.
  1280.     local ($lsearch);
  1281.     local (@dep_list) = ();
  1282.  
  1283.     local ($seen_libobjs) = 0;
  1284.     local ($flagvar) = 0;
  1285.  
  1286.     foreach $lsearch (&variable_value_as_list ($var, $cond))
  1287.     {
  1288.     # Skip -lfoo and -Ldir; these are explicitly allowed.
  1289.     next if $lsearch =~ /^-[lL]/;
  1290.     if (! $flagvar && $lsearch =~ /^-/)
  1291.     {
  1292.         if ($var =~ /^(.*)LDADD$/)
  1293.         {
  1294.         &am_line_error ($var, "linker flags such as \`$lsearch' belong in \`${1}LDFLAGS");
  1295.         }
  1296.         else
  1297.         {
  1298.         # Only get this error once.
  1299.         $flagvar = 1;
  1300.         &am_line_error ($var, "you cannot use linker flags such as \`$lsearch' in \`$var'");
  1301.         }
  1302.     }
  1303.  
  1304.     # Assume we have a file of some sort, and push it onto the
  1305.     # dependency list.  Autoconf substitutions are not pushed;
  1306.     # rarely is a new dependency substituted into (eg) foo_LDADD
  1307.     # -- but "bad things (eg -lX11) are routinely substituted.
  1308.     # Note that LIBOBJS and ALLOCA are exceptions to this rule,
  1309.     # and handled specially below.
  1310.     push (@dep_list, $lsearch)
  1311.         unless $lsearch =~ /^\@.*\@$/;
  1312.  
  1313.     # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
  1314.     # means adding entries to dep_files.
  1315.     if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
  1316.     {
  1317.         push (@dep_list, $lsearch);
  1318.         $seen_libobjs = 1;
  1319.         if (! keys %libsources)
  1320.         {
  1321.         &am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in \`configure.in'");
  1322.         }
  1323.  
  1324.         local ($iter, $rewrite);
  1325.         foreach $iter (keys %libsources)
  1326.         {
  1327.         if ($iter =~ /\.([cly])$/)
  1328.         {
  1329.             &saw_extension ($1);
  1330.             &saw_extension ('c');
  1331.         }
  1332.  
  1333.         if ($iter =~ /\.h$/)
  1334.         {
  1335.             &require_file_with_line ($var, $FOREIGN, $iter);
  1336.         }
  1337.         elsif ($iter ne 'alloca.c')
  1338.         {
  1339.             ($rewrite = $iter) =~ s/\.c$/.P/;
  1340.             $dep_files{'.deps/' . $rewrite} = 1;
  1341.             &require_file_with_line ($var, $FOREIGN, $iter);
  1342.         }
  1343.         }
  1344.     }
  1345.     elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
  1346.     {
  1347.         push (@dep_list, $lsearch);
  1348.         &am_line_error ($var,
  1349.                 "\@$1" . "ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
  1350.         if ! defined $libsources{'alloca.c'};
  1351.         $dep_files{'.deps/alloca.P'} = 1;
  1352.         &require_file_with_line ($var, $FOREIGN, 'alloca.c');
  1353.         &saw_extension ('c');
  1354.     }
  1355.     }
  1356.  
  1357.     if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
  1358.     {
  1359.     &define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
  1360.     }
  1361.  
  1362.     return $seen_libobjs;
  1363. }
  1364.  
  1365. # Canonicalize a name, and check to make sure the non-canonical name
  1366. # is never used.  Returns canonical name.  Arguments are name and a
  1367. # list of suffixes to check for.
  1368. sub check_canonical_spelling
  1369. {
  1370.     local ($name, @suffixes) = @_;
  1371.     local ($xname, $xt);
  1372.  
  1373.     ($xname = $name) =~ tr/A-Za-z0-9_/_/c;
  1374.     if ($xname ne $name)
  1375.     {
  1376.     local ($xt);
  1377.     foreach $xt (@suffixes)
  1378.     {
  1379.         &am_line_error ($name . $xt,
  1380.                 "invalid variable \`" . $name . $xt
  1381.                 . "'; should be \`" . $xname . $xt . "'")
  1382.         if &variable_defined ($name . $xt);
  1383.     }
  1384.     }
  1385.  
  1386.     return $xname;
  1387. }
  1388.  
  1389. # Handle C programs.
  1390. sub handle_programs
  1391. {
  1392.     local (@proglist) = &am_install_var ('-clean',
  1393.                      'progs', 'PROGRAMS',
  1394.                      'bin', 'sbin', 'libexec', 'pkglib',
  1395.                      'noinst', 'check');
  1396.     return if ! @proglist;
  1397.  
  1398.     # If a program is installed, this is required.  We only want this
  1399.     # error to appear once.
  1400.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  1401.     unless $seen_arg_prog;
  1402.     $seen_arg_prog = 1;
  1403.  
  1404.     local ($one_file, $xname, $munge);
  1405.  
  1406.     local ($seen_libobjs) = 0;
  1407.     foreach $one_file (@proglist)
  1408.     {
  1409.     local ($obj) = &get_object_extension ($one_file);
  1410.  
  1411.     # Canonicalize names and check for misspellings.
  1412.     $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
  1413.                         '_SOURCES', '_OBJECTS',
  1414.                         '_DEPENDENCIES');
  1415.  
  1416.     # FIXME: Using a trick to figure out if any lex sources appear
  1417.     # in our program; should use some cleaner method.
  1418.     local ($lex_num) = scalar (keys %lex_sources);
  1419.     local ($linker) = &handle_source_transform ($xname, $one_file, $obj);
  1420.     local ($lex_file_seen) = (scalar (keys %lex_sources) > $lex_num);
  1421.  
  1422.     local ($xt) = '';
  1423.     if (&variable_defined ($xname . "_LDADD"))
  1424.     {
  1425.         if (&handle_lib_objects ($xname, $xname . '_LDADD',
  1426.                      $lex_file_seen))
  1427.         {
  1428.         $seen_libobjs = 1;
  1429.         }
  1430.         $lex_file_seen = 0;
  1431.         $xt = '_LDADD';
  1432.     }
  1433.     else
  1434.     {
  1435.         # User didn't define prog_LDADD override.  So do it.
  1436.         &define_variable ($xname . '_LDADD', '$(LDADD)');
  1437.  
  1438.         # This does a bit too much work.  But we need it to
  1439.         # generate _DEPENDENCIES when appropriate.
  1440.         if (&variable_defined ('LDADD'))
  1441.         {
  1442.         if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
  1443.         {
  1444.             $seen_libobjs = 1;
  1445.         }
  1446.         $lex_file_seen = 0;
  1447.         }
  1448.         elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
  1449.         {
  1450.         &define_variable ($xname . '_DEPENDENCIES', '');
  1451.         }
  1452.         $xt = '_SOURCES'
  1453.     }
  1454.  
  1455.     if (&variable_defined ($xname . '_LIBADD'))
  1456.     {
  1457.         &am_line_error ($xname . '_LIBADD',
  1458.                 "use \`" . $xname . "_LDADD', not \`"
  1459.                 . $xname . "_LIBADD'");
  1460.     }
  1461.  
  1462.     if (! &variable_defined ($xname . '_LDFLAGS'))
  1463.     {
  1464.         # Define the prog_LDFLAGS variable.
  1465.         &define_variable ($xname . '_LDFLAGS', '');
  1466.     }
  1467.  
  1468.     # Determine program to use for link.
  1469.     local ($xlink);
  1470.     if (&variable_defined ($xname . '_LINK'))
  1471.     {
  1472.         $xlink = $xname . '_LINK';
  1473.     }
  1474.     else
  1475.     {
  1476.         $xlink = $linker ? $linker : 'LINK';
  1477.     }
  1478.  
  1479.     local ($xexe);
  1480.     if ($seen_exeext && $one_file !~ /\./)
  1481.     {
  1482.         $xexe = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
  1483.     }
  1484.     else
  1485.     {
  1486.         $xexe = 's/\@EXEEXT\@//g;';
  1487.     }
  1488.  
  1489.     $output_rules .=
  1490.         &file_contents_with_transform
  1491.         ('s/\@PROGRAM\@/' . $one_file . '/go;'
  1492.          . 's/\@XPROGRAM\@/' . $xname . '/go;'
  1493.          . 's/\@XLINK\@/' . $xlink . '/go;'
  1494.          . $xexe,
  1495.          'program');
  1496.     }
  1497.  
  1498.     if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
  1499.     {
  1500.     $seen_libobjs = 1;
  1501.     }
  1502.  
  1503.     if ($seen_libobjs)
  1504.     {
  1505.     foreach $one_file (@proglist)
  1506.     {
  1507.         # Canonicalize names.
  1508.         ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
  1509.  
  1510.         if (&variable_defined ($xname . '_LDADD'))
  1511.         {
  1512.         &check_libobjs_sources ($xname, $xname . '_LDADD');
  1513.         }
  1514.         elsif (&variable_defined ('LDADD'))
  1515.         {
  1516.         &check_libobjs_sources ($xname, 'LDADD');
  1517.         }
  1518.     }
  1519.     }
  1520. }
  1521.  
  1522.  
  1523. # Handle libraries.
  1524. sub handle_libraries
  1525. {
  1526.     local (@liblist) = &am_install_var ('-clean',
  1527.                     'libs', 'LIBRARIES',
  1528.                     'lib', 'pkglib', 'noinst', 'check');
  1529.     return if ! @liblist;
  1530.  
  1531.     local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
  1532.                        'noinst', 'check');
  1533.     if (! defined $configure_vars{'RANLIB'})
  1534.     {
  1535.     local ($key);
  1536.     foreach $key (keys %valid)
  1537.     {
  1538.         if (&variable_defined ($key . '_LIBRARIES'))
  1539.         {
  1540.         &am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
  1541.         # Only get this error once.  If this is ever printed,
  1542.         # we have a bug.
  1543.         $configure_vars{'RANLIB'} = 'BUG';
  1544.         last;
  1545.         }
  1546.     }
  1547.     }
  1548.  
  1549.     local ($onelib);
  1550.     local ($munge);
  1551.     local ($xlib);
  1552.     local ($seen_libobjs) = 0;
  1553.     foreach $onelib (@liblist)
  1554.     {
  1555.     # Check that the library fits the standard naming convention.
  1556.     if ($onelib !~ /^lib.*\.a$/)
  1557.     {
  1558.         # FIXME should put line number here.  That means mapping
  1559.         # from library name back to variable name.
  1560.         &am_error ("\`$onelib' is not a standard library name");
  1561.     }
  1562.  
  1563.     local ($obj) = &get_object_extension ($onelib);
  1564.  
  1565.     # Canonicalize names and check for misspellings.
  1566.     $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
  1567.                        '_OBJECTS', '_DEPENDENCIES');
  1568.  
  1569.     if (&variable_defined ($xlib . '_LIBADD'))
  1570.     {
  1571.         if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
  1572.         {
  1573.         $seen_libobjs = 1;
  1574.         }
  1575.     }
  1576.     else
  1577.     {
  1578.         # Generate support for conditional object inclusion in
  1579.         # libraries.
  1580.         &define_variable ($xlib . "_LIBADD", '');
  1581.     }
  1582.  
  1583.     if (&variable_defined ($xlib . '_LDADD'))
  1584.     {
  1585.         &am_line_error ($xlib . '_LDADD',
  1586.                 "use \`" . $xlib . "_LIBADD', not \`"
  1587.                 . $xlib . "_LDADD'");
  1588.     }
  1589.  
  1590.     # Make sure we at look at this.
  1591.     &examine_variable ($xlib . '_DEPENDENCIES');
  1592.  
  1593.     &handle_source_transform ($xlib, $onelib, $obj);
  1594.  
  1595.     $output_rules .=
  1596.         &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
  1597.                        . 's/\@XLIBRARY\@/'
  1598.                        . $xlib . '/go;',
  1599.                        'library');
  1600.     }
  1601.  
  1602.     if ($seen_libobjs)
  1603.     {
  1604.     foreach $onelib (@liblist)
  1605.     {
  1606.         # Canonicalize names.
  1607.         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
  1608.         if (&variable_defined ($xlib . '_LIBADD'))
  1609.         {
  1610.         &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
  1611.         }
  1612.     }
  1613.     }
  1614.  
  1615.     &define_variable ('AR', 'ar');
  1616.     &define_configure_variable ('RANLIB');
  1617. }
  1618.  
  1619. # Handle shared libraries.
  1620. sub handle_ltlibraries
  1621. {
  1622.     local (@liblist) = &am_install_var ('-clean',
  1623.                     'ltlib', 'LTLIBRARIES',
  1624.                     'noinst', 'lib', 'pkglib');
  1625.     return if ! @liblist;
  1626.  
  1627.     local (%instdirs);
  1628.     local (%valid) = &am_primary_prefixes ('LTLIBRARIES', 'lib', 'pkglib',
  1629.                        'noinst');
  1630.  
  1631.     local ($key);
  1632.     foreach $key (keys %valid)
  1633.     {
  1634.     if (&variable_defined ($key . '_LTLIBRARIES'))
  1635.     {
  1636.         if (!$seen_libtool)
  1637.         {
  1638.         &am_line_error ($key . '_LTLIBRARIES', "library used but \`LIBTOOL' not defined in \`configure.in'");
  1639.         # Only get this error once.  If this is ever printed,
  1640.         # we have a bug.
  1641.         $configure_vars{'LIBTOOL'} = 'BUG';
  1642.         $seen_libtool = 1;
  1643.         }
  1644.  
  1645.         # Get the installation directory of each library.
  1646.         for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
  1647.         {
  1648.         if ($instdirs{$_})
  1649.         {
  1650.             &am_error ("\`$_' is already going to be installed in \`$instdirs{$_}'");
  1651.         }
  1652.         else
  1653.         {
  1654.             $instdirs{$_} = $key;
  1655.         }
  1656.         }
  1657.     }
  1658.     }
  1659.  
  1660.     local ($onelib);
  1661.     local ($munge);
  1662.     local ($xlib);
  1663.     local ($seen_libobjs) = 0;
  1664.     foreach $onelib (@liblist)
  1665.     {
  1666.     local ($obj) = &get_object_extension ($onelib);
  1667.  
  1668.     # Canonicalize names and check for misspellings.
  1669.     $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
  1670.                        '_SOURCES', '_OBJECTS',
  1671.                        '_DEPENDENCIES');
  1672.  
  1673.     if (! &variable_defined ($xlib . '_LDFLAGS'))
  1674.     {
  1675.         # Define the lib_LDFLAGS variable.
  1676.         &define_variable ($xlib . '_LDFLAGS', '');
  1677.     }
  1678.  
  1679.     # Check that the library fits the standard naming convention.
  1680.         $libname_rx = "^lib.*\.la";
  1681.     if (&variable_value ($xlib . '_LDFLAGS') =~ /-module/) 
  1682.     {
  1683.         # Relax name checking for libtool modules.
  1684.             $libname_rx = "\.la";
  1685.     }
  1686.     if ($onelib !~ /$libname_rx$/)
  1687.     {
  1688.         # FIXME this should only be a warning for foreign packages
  1689.         # FIXME should put line number here.  That means mapping
  1690.         # from library name back to variable name.
  1691.         &am_error ("\`$onelib' is not a standard libtool library name");
  1692.     }
  1693.  
  1694.     if (&variable_defined ($xlib . '_LIBADD'))
  1695.     {
  1696.         if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
  1697.         {
  1698.         $seen_libobjs = 1;
  1699.         }
  1700.     }
  1701.     else
  1702.     {
  1703.         # Generate support for conditional object inclusion in
  1704.         # libraries.
  1705.         &define_variable ($xlib . "_LIBADD", '');
  1706.     }
  1707.  
  1708.     if (&variable_defined ($xlib . '_LDADD'))
  1709.     {
  1710.         &am_line_error ($xlib . '_LDADD',
  1711.                 "use \`" . $xlib . "_LIBADD', not \`"
  1712.                 . $xlib . "_LDADD'");
  1713.     }
  1714.  
  1715.     # Make sure we at look at this.
  1716.     &examine_variable ($xlib . '_DEPENDENCIES');
  1717.  
  1718.     local ($linker) = &handle_source_transform ($xlib, $onelib, $obj);
  1719.  
  1720.     # Determine program to use for link.
  1721.     local ($xlink);
  1722.     if (&variable_defined ($xlib . '_LINK'))
  1723.     {
  1724.         $xlink = $xlib . '_LINK';
  1725.     }
  1726.     else
  1727.     {
  1728.         $xlink = $linker ? $linker : 'LINK';
  1729.     }
  1730.  
  1731.     local ($rpath);
  1732.     if ($instdirs{$onelib} eq 'EXTRA' || $instdirs{$onelib} eq 'noinst')
  1733.     {
  1734.         # It's an EXTRA_ library, so we can't specify -rpath,
  1735.         # because we don't know where the library will end up.
  1736.         # The user probably knows, but generally speaking automake
  1737.         # doesn't -- and in fact configure could decide
  1738.         # dynamically between two different locations.
  1739.         $rpath = 's/\@RPATH\@//go;';
  1740.     }
  1741.     else
  1742.     {
  1743.         $rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
  1744.               . 'dir)/go;');
  1745.     }
  1746.  
  1747.     $output_rules .=
  1748.         &file_contents_with_transform ('s/\@LTLIBRARY\@/'
  1749.                        . $onelib . '/go;'
  1750.                        . 's/\@XLTLIBRARY\@/'
  1751.                        . $xlib . '/go;'
  1752.                        . $rpath
  1753.                        . 's/\@XLINK\@/' . $xlink . '/go;',
  1754.                        'ltlibrary');
  1755.     }
  1756.  
  1757.     if ($seen_libobjs)
  1758.     {
  1759.     foreach $onelib (@liblist)
  1760.     {
  1761.         # Canonicalize names.
  1762.         ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
  1763.         if (&variable_defined ($xlib . '_LIBADD'))
  1764.         {
  1765.         &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
  1766.         }
  1767.     }
  1768.     }
  1769. }
  1770.  
  1771. # See if any _SOURCES variable were misspelled.  Also, make sure that
  1772. # EXTRA_ variables don't contain configure substitutions.
  1773. sub check_typos
  1774. {
  1775.     local ($varname, $primary);
  1776.     foreach $varname (keys %contents)
  1777.     {
  1778.     foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
  1779.               '_DEPENDENCIES')
  1780.     {
  1781.         if ($varname =~ /$primary$/ && ! $content_seen{$varname})
  1782.         {
  1783.         &am_line_error ($varname,
  1784.                 "invalid unused variable name: \`$varname'");
  1785.         }
  1786.     }
  1787.     }
  1788. }
  1789.  
  1790. # Handle scripts.
  1791. sub handle_scripts
  1792. {
  1793.     # NOTE we no longer automatically clean SCRIPTS, because it is
  1794.     # useful to sometimes distribute scripts verbatim.  This happens
  1795.     # eg in Automake itself.
  1796.     &am_install_var ('scripts', 'SCRIPTS',
  1797.              'bin', 'sbin', 'libexec', 'pkgdata',
  1798.              'noinst', 'check');
  1799.  
  1800.     local ($scripts_installed) = 0;
  1801.     # Set $scripts_installed if appropriate.  Make sure we only find
  1802.     # scripts which are actually installed -- this is why we can't
  1803.     # simply use the return value of am_install_var.
  1804.     local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
  1805.                        'libexec', 'pkgdata',
  1806.                        'noinst', 'check');
  1807.     local ($key);
  1808.     foreach $key (keys %valid)
  1809.     {
  1810.     if ($key ne 'noinst'
  1811.         && $key ne 'check'
  1812.         && &variable_defined ($key . '_SCRIPTS'))
  1813.     {
  1814.         $scripts_installed = 1;
  1815.         # push (@check_tests, 'check-' . $key . 'SCRIPTS');
  1816.     }
  1817.     }
  1818.  
  1819.     if ($scripts_installed)
  1820.     {
  1821.     # If a program is installed, this is required.  We only want this
  1822.     # error to appear once.
  1823.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  1824.         unless $seen_arg_prog;
  1825.     $seen_arg_prog = 1;
  1826.     }
  1827. }
  1828.  
  1829. # Search a file for a "version.texi" Texinfo include.  Return the name
  1830. # of the include file if found, or the empty string if not.  A
  1831. # "version.texi" file is actually any file whose name matches
  1832. # "vers*.texi".
  1833. sub scan_texinfo_file
  1834. {
  1835.     local ($filename) = @_;
  1836.  
  1837.     if (! open (TEXI, $filename))
  1838.     {
  1839.     &am_error ("couldn't open \`$filename': $!");
  1840.     return '';
  1841.     }
  1842.     print "automake: reading $filename\n" if $verbose;
  1843.  
  1844.     local ($vfile, $outfile);
  1845.     while (<TEXI>)
  1846.     {
  1847.     if (/^\@setfilename +(\S+)/)
  1848.     {
  1849.         $outfile = $1;
  1850.         last if ($vfile);
  1851.     }
  1852.  
  1853.     if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
  1854.     {
  1855.         # Found version.texi include.
  1856.         $vfile = $1;
  1857.         last if $outfile;
  1858.     }
  1859.     }
  1860.  
  1861.     close (TEXI);
  1862.     return ($outfile, $vfile);
  1863. }
  1864.  
  1865. # Handle all Texinfo source.
  1866. sub handle_texinfo
  1867. {
  1868.     &am_line_error ('TEXINFOS',
  1869.             "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
  1870.     if &variable_defined ('TEXINFOS');
  1871.     return if (! &variable_defined ('info_TEXINFOS')
  1872.            && ! &variable_defined ('html_TEXINFOS'));
  1873.  
  1874.     if (&variable_defined ('html_TEXINFOS'))
  1875.     {
  1876.     &am_line_error ('html_TEXINFOS',
  1877.             "HTML generation not yet supported");
  1878.     return;
  1879.     }
  1880.  
  1881.     local (@texis) = &variable_value_as_list ('info_TEXINFOS', 'all');
  1882.  
  1883.     local (@info_deps_list, @dvis_list, @texi_deps);
  1884.     local ($infobase, $info_cursor);
  1885.     local (%versions);
  1886.     local ($done) = 0;
  1887.     local ($vti);
  1888.     local ($tc_cursor, @texi_cleans);
  1889.     local ($canonical);
  1890.  
  1891.     foreach $info_cursor (@texis)
  1892.     {
  1893.     # FIXME: This is mildly hacky, since it recognizes "txinfo".
  1894.     # I don't feel like making it right.
  1895.     ($infobase = $info_cursor) =~ s/\.te?xi(nfo)?$//;
  1896.  
  1897.     # If 'version.texi' is referenced by input file, then include
  1898.     # automatic versioning capability.
  1899.     local ($out_file, $vtexi) = &scan_texinfo_file ($relative_dir
  1900.                             . "/" . $info_cursor);
  1901.  
  1902.     if ($out_file eq '')
  1903.     {
  1904.         &am_error ("\`$info_cursor' missing \@setfilename");
  1905.         next;
  1906.     }
  1907.  
  1908.     if ($out_file =~ /\.(.+)$/ && $1 ne 'info')
  1909.     {
  1910.         # FIXME should report line number in input file.
  1911.         &am_error ("output of \`$info_cursor', \`$out_file', has unrecognized extension");
  1912.         next;
  1913.     }
  1914.  
  1915.     if ($vtexi)
  1916.     {
  1917.         &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
  1918.         if (defined $versions{$vtexi});
  1919.         $versions{$vtexi} = $info_cursor;
  1920.  
  1921.         # We number the stamp-vti files.  This is doable since the
  1922.         # actual names don't matter much.  We only number starting
  1923.         # with the second one, so that the common case looks nice.
  1924.         $vti = 'vti' . ($done ? $done : '');
  1925.         &push_dist_common ($vtexi, 'stamp-' . $vti);
  1926.         push (@clean, $vti);
  1927.  
  1928.         # Only require once.
  1929.         &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
  1930.                       'mdate-sh')
  1931.         if ! $done;
  1932.         ++$done;
  1933.  
  1934.         local ($conf_pat, $conf_dir);
  1935.         if ($config_aux_dir eq '.' || $config_aux_dir eq '')
  1936.         {
  1937.         $conf_dir = '$(srcdir)/';
  1938.         }
  1939.         else
  1940.         {
  1941.         $conf_dir = $config_aux_dir;
  1942.         $conf_dir .= '/' unless $conf_dir =~ /\/$/;
  1943.         }
  1944.         ($conf_pat = $conf_dir) =~ s/(\W)/\\$1/g;
  1945.         $output_rules .=
  1946.         &file_contents_with_transform
  1947.             ('s/\@TEXI\@/' . $info_cursor . '/g; '
  1948.              . 's/\@VTI\@/' . $vti . '/g; '
  1949.              . 's/\@VTEXI\@/' . $vtexi . '/g;'
  1950.              . 's,\@MDDIR\@,' . $conf_pat . ',g;',
  1951.              'texi-vers');
  1952.  
  1953.         &push_phony_cleaners ($vti);
  1954.     }
  1955.  
  1956.     # If user specified file_TEXINFOS, then use that as explicit
  1957.     # dependency list.
  1958.     @texi_deps = ();
  1959.     push (@texi_deps, $info_cursor);
  1960.     push (@texi_deps, $vtexi) if $vtexi;
  1961.  
  1962.     # Canonicalize name first.
  1963.     ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
  1964.     if (&variable_defined ($canonical . "_TEXINFOS"))
  1965.     {
  1966.         push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
  1967.         &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
  1968.     }
  1969.  
  1970.     $output_rules .= ("\n" . $out_file . ": "
  1971.               . join (' ', @texi_deps)
  1972.               . "\n" . $infobase . ".dvi: "
  1973.               . join (' ', @texi_deps)
  1974.               . "\n\n");
  1975.  
  1976.     push (@info_deps_list, $out_file);
  1977.     push (@dvis_list, $infobase . '.dvi');
  1978.  
  1979.     # Generate list of things to clean for this target.  We do
  1980.     # this explicitly because otherwise too many things could be
  1981.     # removed.  In particular the ".log" extension might
  1982.     # reasonably be used in other contexts by the user.
  1983.     foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
  1984.                 'ky', 'kys', 'ps', 'log', 'pg', 'toc', 'tp', 'tps',
  1985.                 'vr', 'vrs', 'op', 'tr', 'cv', 'cn')
  1986.     {
  1987.         push (@texi_cleans, $infobase . '.' . $tc_cursor);
  1988.     }
  1989.     }
  1990.  
  1991.     # Find these programs wherever they may lie.  Yes, this has
  1992.     # intimate knowledge of the structure of the texinfo distribution.
  1993.     &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
  1994.                   'makeinfo',
  1995.                   # Circumlocution to avoid accidental
  1996.                   # configure substitution.
  1997.                   '@MAKE' . 'INFO@');
  1998.     &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
  1999.                   'texi2dvi');
  2000.  
  2001.     # Set transform for including texinfos.am.  First, handle --cygnus
  2002.     # stuff.
  2003.     local ($xform);
  2004.     if ($cygnus_mode)
  2005.     {
  2006.     $xform = 's/^NOTCYGNUS.*$//; s/^CYGNUS//;';
  2007.     }
  2008.     else
  2009.     {
  2010.     $xform = 's/^CYGNUS.*$//; s/^NOTCYGNUS//;';
  2011.     }
  2012.  
  2013.     # Handle location of texinfo.tex.
  2014.     local ($need_texi_file) = 0;
  2015.     local ($texinfo_tex);
  2016.     if ($cygnus_mode)
  2017.     {
  2018.     $texinfo_tex = '$(top_srcdir)/../texinfo/texinfo.tex';
  2019.     &define_variable ('TEXINFO_TEX', $texinfo_tex);
  2020.  
  2021.     }
  2022.     elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
  2023.     {
  2024.     $texinfo_tex = $config_aux_dir . '/texinfo.tex';
  2025.     &define_variable ('TEXINFO_TEX', $texinfo_tex);
  2026.     }
  2027.     elsif (&variable_defined ('TEXINFO_TEX'))
  2028.     {
  2029.     # The user defined TEXINFO_TEX so assume he knows what he is
  2030.     # doing.
  2031.     $texinfo_tex = ('$(srcdir)/'
  2032.             . &dirname (&variable_value ('TEXINFO_TEX')));
  2033.     }
  2034.     else
  2035.     {
  2036.     $texinfo_tex = '.';
  2037.     $need_texi_file = 1;
  2038.     }
  2039.     local ($xxform);
  2040.     ($xxform = $texinfo_tex) =~ s/(\W)/\\$1/g;
  2041.     $xform .= ' s/\@TEXINFODIR\@/' . $xxform . '/g;';
  2042.  
  2043.     $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
  2044.     push (@phony, 'install-info-am', 'uninstall-info');
  2045.     push (@dist_targets, 'dist-info');
  2046.  
  2047.     # How to clean.  The funny name is due to --cygnus influence; in
  2048.     # Cygnus mode, `clean-info' is a target that users can use.
  2049.     $output_rules .= "\nmostlyclean-aminfo:\n";
  2050.     &pretty_print_rule ("\t-rm -f", "\t  ", @texi_cleans);
  2051.     $output_rules .= ("\nclean-aminfo:\n\ndistclean-aminfo:\n\n"
  2052.               . "maintainer-clean-aminfo:\n\t"
  2053.               # Eww.  But how else can we find all the output
  2054.               # files from makeinfo?
  2055.               . ($cygnus_mode ? '' : 'cd $(srcdir) && ')
  2056.               . 'for i in $(INFO_DEPS); do' . " \\\n"
  2057.               . "\t" . '  rm -f $$i;' . " \\\n"
  2058.               . "\t" . '  if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then' . " \\\n"
  2059.               . "\t" . '    rm -f $$i-[0-9]*;' . " \\\n"
  2060.               . "\t" . '  fi;' . " \\\n"
  2061.               . "\tdone\n");
  2062.     &push_phony_cleaners ('aminfo');
  2063.     if ($cygnus_mode)
  2064.     {
  2065.     $output_rules .= "clean-info: mostlyclean-aminfo\n";
  2066.     }
  2067.  
  2068.     push (@suffixes, '.texi', '.texinfo', '.txi', '.info', '.dvi', '.ps');
  2069.  
  2070.     if (! defined $options{'no-installinfo'})
  2071.     {
  2072.     push (@uninstall, 'uninstall-info');
  2073.     push (@installdirs, '$(DESTDIR)$(infodir)');
  2074.     unshift (@install_data, 'install-info-am');
  2075.  
  2076.     # Make sure documentation is made and installed first.  Use
  2077.     # $(INFO_DEPS), not 'info', because otherwise recursive makes
  2078.     # get run twice during "make all".
  2079.     unshift (@all, '$(INFO_DEPS)');
  2080.     }
  2081.     push (@clean, 'aminfo');
  2082.     push (@info, '$(INFO_DEPS)');
  2083.     push (@dvi, '$(DVIS)');
  2084.  
  2085.     &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
  2086.     &define_variable ("DVIS", join (' ', @dvis_list));
  2087.     # This next isn't strictly needed now -- the places that look here
  2088.     # could easily be changed to look in info_TEXINFOS.  But this is
  2089.     # probably better, in case noinst_TEXINFOS is ever supported.
  2090.     &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));
  2091.  
  2092.     # Do some error checking.  Note that this file is not required
  2093.     # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
  2094.     # up above.
  2095.     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex')
  2096.     if $need_texi_file && ! defined $options{'no-texinfo.tex'};
  2097. }
  2098.  
  2099. # Handle any man pages.
  2100. sub handle_man_pages
  2101. {
  2102.     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
  2103.     if &variable_defined ('MANS');
  2104.     return if ! &variable_defined ('man_MANS');
  2105.  
  2106.     # Find all the sections in use.  We do this by first looking for
  2107.     # "standard" sections, and then looking for any additional
  2108.     # sections used in man_MANS.
  2109.     local ($sect, %sections, %vlist);
  2110.     # Add more sections as needed.
  2111.     foreach $sect ('0'..'9', 'n', 'l')
  2112.     {
  2113.     if (&variable_defined ('man' . $sect . '_MANS'))
  2114.     {
  2115.         $sections{$sect} = 1;
  2116.         $vlist{'$(man' . $sect . '_MANS)'} = 1;
  2117.     }
  2118.     }
  2119.  
  2120.     if (&variable_defined ('man_MANS'))
  2121.     {
  2122.     $vlist{'$(man_MANS)'} = 1;
  2123.     foreach (&variable_value_as_list ('man_MANS', 'all'))
  2124.     {
  2125.         # A page like `foo.1c' goes into man1dir.
  2126.         if (/\.([0-9a-z])([a-z]*)$/)
  2127.         {
  2128.         $sections{$1} = 1;
  2129.         }
  2130.     }
  2131.     }
  2132.  
  2133.  
  2134.     # Now for each section, generate an install and unintall rule.
  2135.     # Sort sections so output is deterministic.
  2136.     local (@namelist);
  2137.     foreach $sect (sort keys %sections)
  2138.     {
  2139.     &define_variable ('man' . $sect . 'dir', '$(mandir)/man' . $sect);
  2140.     push (@installdirs, '$(DESTDIR)$(mandir)/man' . $sect)
  2141.         unless defined $options{'no-installman'};
  2142.     $output_rules .= &file_contents_with_transform ('s/\@SECTION\@/'
  2143.                             . $sect . '/g;',
  2144.                             'mans');
  2145.     push (@phony, 'install-man' . $sect, 'uninstall-man' . $sect);
  2146.     push (@namelist, 'install-man' . $sect);
  2147.     }
  2148.  
  2149.     # We don't really need this, but we use it in case we ever want to
  2150.     # support noinst_MANS.
  2151.     &define_variable ("MANS", join (' ', sort keys %vlist));
  2152.  
  2153.     # Generate list of install dirs.
  2154.     $output_rules .= ("install-man: \$(MANS)\n"
  2155.               . "\t\@\$(NORMAL_INSTALL)\n");
  2156.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
  2157.     push (@phony, 'install-man');
  2158.  
  2159.     $output_rules .= "uninstall-man:\n\t\@\$(NORMAL_UNINSTALL)\n";
  2160.     grep ($_ = 'un' . $_, @namelist);
  2161.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t ", @namelist);
  2162.     push (@phony, 'uninstall-man');
  2163.  
  2164.     $output_vars .= &file_contents ('mans-vars');
  2165.  
  2166.     if (! defined $options{'no-installman'})
  2167.     {
  2168.     push (@install_data, 'install-man');
  2169.     push (@uninstall, 'uninstall-man');
  2170.     push (@all, '$(MANS)');
  2171.     }
  2172. }
  2173.  
  2174. # Handle DATA variables.
  2175. sub handle_data
  2176. {
  2177.     &am_install_var ('-noextra', 'data', 'DATA', 'data', 'sysconf',
  2178.              'sharedstate', 'localstate', 'pkgdata',
  2179.              'noinst', 'check');
  2180. }
  2181.  
  2182. # Handle TAGS.
  2183. sub handle_tags
  2184. {
  2185.     push (@phony, 'tags');
  2186.     local (@tag_deps) = ();
  2187.     if (&variable_defined ('SUBDIRS'))
  2188.     {
  2189.     $output_rules .= ("tags-recursive:\n"
  2190.               . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
  2191.               # Never fail here if a subdir fails; it
  2192.               # isn't important.
  2193.               . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
  2194.               . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
  2195.               . "\tdone\n");
  2196.     push (@tag_deps, 'tags-recursive');
  2197.     push (@phony, 'tags-recursive');
  2198.     }
  2199.  
  2200.     if (&saw_sources_p (1)
  2201.     || &variable_defined ('ETAGS_ARGS')
  2202.     || @tag_deps)
  2203.     {
  2204.     local ($xform) = '';
  2205.     local ($one_hdr);
  2206.     foreach $one_hdr (@config_headers)
  2207.     {
  2208.         if ($relative_dir eq &dirname ($one_hdr))
  2209.         {
  2210.         # The config header is in this directory.  So require it.
  2211.         local ($var);
  2212.         ($var = &basename ($one_hdr)) =~ s/(\W)/\\$1/g;
  2213.         $xform .= ' ' if $xform;
  2214.         $xform .= $var;
  2215.         }
  2216.     }
  2217.     $xform = ('s/\@CONFIG\@/' . $xform . '/;'
  2218.           . 's/\@DIRS\@/' . join (' ', @tag_deps) . '/;');
  2219.  
  2220.     if (&variable_defined ('SUBDIRS'))
  2221.     {
  2222.         $xform .= 's/^SUBDIRS//;';
  2223.     }
  2224.     else
  2225.     {
  2226.         $xform .= 's/^SUBDIRS.*$//;';
  2227.     }
  2228.  
  2229.     $output_rules .= &file_contents_with_transform ($xform, 'tags');
  2230.     $output_rules .= &file_contents ('tags-clean');
  2231.     push (@clean, 'tags');
  2232.     &push_phony_cleaners ('tags');
  2233.     &examine_variable ('TAGS_DEPENDENCIES');
  2234.     }
  2235.     elsif (&variable_defined ('TAGS_DEPENDENCIES'))
  2236.     {
  2237.     &am_line_error ('TAGS_DEPENDENCIES',
  2238.             "doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
  2239.     }
  2240.     else
  2241.     {
  2242.     # Every Makefile must define some sort of TAGS rule.
  2243.     # Otherwise, it would be possible for a top-level "make TAGS"
  2244.     # to fail because some subdirectory failed.
  2245.     $output_rules .= "tags: TAGS\nTAGS:\n\n";
  2246.     }
  2247. }
  2248.  
  2249. # Handle multilib support.
  2250. sub handle_multilib
  2251. {
  2252.     return unless $seen_multilib;
  2253.  
  2254.     $output_rules .= &file_contents ('multilib.am');
  2255.     &push_phony_cleaners ('multi');
  2256.     push (@phony, 'all-multi', 'install-multi');
  2257. }
  2258.  
  2259. # Worker for handle_dist.
  2260. sub handle_dist_worker
  2261. {
  2262.     local ($makefile) = @_;
  2263.  
  2264.     $output_rules .= 'distdir: $(DISTFILES)' . "\n";
  2265.  
  2266.     # Initialization; only at top level.
  2267.     if ($relative_dir eq '.')
  2268.     {
  2269.     if (defined $options{'check-news'})
  2270.     {
  2271.         # For Gnits users, this is pretty handy.  Look at 15 lines
  2272.         # in case some explanatory text is desirable.
  2273.         $output_rules .= '    @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
  2274.       echo "NEWS not updated; not releasing" 1>&2; \\
  2275.       exit 1; \\
  2276.     fi
  2277. ';
  2278.     }
  2279.  
  2280.  
  2281.     # Create dist directory.
  2282.     $output_rules .= ("\t-rm -rf \$(distdir)\n"
  2283.               . "\tmkdir \$(distdir)\n"
  2284.               . "\t-chmod 777 \$(distdir)\n");
  2285.     }
  2286.  
  2287.     # Only run automake in `dist' target if --include-deps and
  2288.     # `no-dependencies' not specified.  That way the recipient of a
  2289.     # distribution can run "make dist" and not need Automake.  You
  2290.     # might be wondering why we run automake once for each directory
  2291.     # we distribute, instead of running it once at the top level.  The
  2292.     # answer is that we want to run automake after the dependencies
  2293.     # have been generated.  This occurs when "make" is run in the
  2294.     # subdir.  So automake must be run after make has updated the
  2295.     # Makefile, which means that it must run once per directory.
  2296.     if ($use_dependencies)
  2297.     {
  2298.     $output_rules .=
  2299.         (
  2300.          # There are several directories we need to know about
  2301.          # when rebuilding the Makefile.ins.  They are:
  2302.          #   here - The absolute path to our topmost build directory.
  2303.          #   top_distdir - The absolute path to the top of our dist
  2304.          #                 hierarchy.
  2305.          #   distdir - The path to our sub-part of the dist hierarchy.
  2306.          # If this directory is the topmost directory, we set
  2307.          # top_distdir from distdir; that lets us pass in distdir
  2308.          # from an enclosing package.
  2309.          "\t" . 'here=`cd $(top_builddir) && pwd`; ' . "\\\n"
  2310.          . "\t" . 'top_distdir=`cd $('
  2311.          . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
  2312.          . ') && pwd`; ' . "\\\n"
  2313.          . "\t" . 'distdir=`cd $(distdir) && pwd`; ' . "\\\n"
  2314.          . "\tcd \$(top_srcdir) \\\n"
  2315.          . "\t  && \$(AUTOMAKE) --include-deps --build-dir=\$\$here --srcdir-name=\$(top_srcdir) --output-dir=\$\$top_distdir "
  2316.          # Set strictness of output.
  2317.          . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
  2318.          . ($cmdline_use_dependencies ? '' : ' --include-deps')
  2319.          . " " . $makefile . "\n"
  2320.          );
  2321.     }
  2322.  
  2323.     # Scan EXTRA_DIST to see if we need to distribute anything from a
  2324.     # subdir.  If so, add it to the list.  I didn't want to do this
  2325.     # originally, but there were so many requests that I finally
  2326.     # relented.
  2327.     local (@dist_dirs);
  2328.     if (&variable_defined ('EXTRA_DIST'))
  2329.     {
  2330.     # FIXME: This should be fixed to work with conditionals.  That
  2331.     # will require only making the entries in @dist_dirs under the
  2332.     # appropriate condition.  This is meaningful if the nature of
  2333.     # the distribution should depend upon the configure options
  2334.     # used.
  2335.     foreach (&variable_value_as_list ('EXTRA_DIST', ''))
  2336.     {
  2337.         next if /^\@.*\@$/;
  2338.         next unless s,/+[^/]+$,,;
  2339.         push (@dist_dirs, $_)
  2340.         unless $_ eq '.';
  2341.     }
  2342.     }
  2343.     if (@dist_dirs)
  2344.     {
  2345.     # Prepend $(distdir) to each directory given.  Doing it via a
  2346.     # hash lets us ensure that each directory is used only once.
  2347.     local (%dhash);
  2348.     grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
  2349.     $output_rules .= "\t";
  2350.     &pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
  2351.     }
  2352.  
  2353.     # In loop, test for file existence because sometimes a file gets
  2354.     # included in DISTFILES twice.  For example this happens when a
  2355.     # single source file is used in building more than one program.
  2356.     # Also, there are situations in which "ln" can fail.  For instance
  2357.     # a file to distribute could actually be a cross-filesystem
  2358.     # symlink -- this can easily happen if "gettextize" was run on the
  2359.     # distribution.
  2360.     $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
  2361.     if ($cygnus_mode)
  2362.     {
  2363.     $output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
  2364.     }
  2365.     else
  2366.     {
  2367.     $output_rules .= "\t  d=\$(srcdir); \\\n";
  2368.     }
  2369.     $output_rules .= ("\t  if test -d \$\$d/\$\$file; then \\\n"
  2370.               . "\t    cp -pr \$\$/\$\$file \$(distdir)/\$\$file; \\\n"
  2371.               . "\t  else \\\n"
  2372.               . "\t    test -f \$(distdir)/\$\$file \\\n"
  2373.               . "\t    || ln \$\$d/\$\$file \$(distdir)/\$\$file 2> /dev/null \\\n"
  2374.               . "\t    || cp -p \$\$d/\$\$file \$(distdir)/\$\$file || :; \\\n"
  2375.               . "\t  fi; \\\n"
  2376.               . "\tdone\n");
  2377.  
  2378.     # If we have SUBDIRS, create all dist subdirectories and do
  2379.     # recursive build.
  2380.     if (&variable_defined ('SUBDIRS'))
  2381.     {
  2382.     # If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
  2383.     # to all possible directories, and use it.  If DIST_SUBDIRS is
  2384.     # defined, just use it.
  2385.     local ($dist_subdir_name);
  2386.     if (&variable_conditions ('SUBDIRS')
  2387.         || &variable_defined ('DIST_SUBDIRS'))
  2388.     {
  2389.         $dist_subdir_name = 'DIST_SUBDIRS';
  2390.         if (! &variable_defined ('DIST_SUBDIRS'))
  2391.         {
  2392.         &define_pretty_variable ('DIST_SUBDIRS', '',
  2393.                      &variable_value_as_list ('SUBDIRS',
  2394.                                   'all'));
  2395.         }
  2396.     }
  2397.     else
  2398.     {
  2399.         $dist_subdir_name = 'SUBDIRS';
  2400.     }
  2401.  
  2402.     # Test for directory existence here because previous automake
  2403.     # invocation might have created some directories.  Note that
  2404.     # we explicitly set distdir for the subdir make; that lets us
  2405.     # mix-n-match many automake-using packages into one large
  2406.     # package, and have "dist" at the top level do the right
  2407.     # thing.  If we're in the topmost directory, then we use
  2408.     # `distdir' instead of `top_distdir'; this lets us work
  2409.     # correctly with an enclosing package.
  2410.     $output_rules .= 
  2411.         ("\t" . 'for subdir in $(' . $dist_subdir_name . '); do ' . "\\\n"
  2412.          . "\t" . '  if test "$$subdir" = .; then :; else ' . "\\\n"
  2413.          . "\t" . '    test -d $(distdir)/$$subdir ' . "\\\n"
  2414.          . "\t" . '    || mkdir $(distdir)/$$subdir ' . "\\\n"
  2415.          . "\t" . '    || exit 1; ' . "\\\n"
  2416.          . "\t" . '    chmod 777 $(distdir)/$$subdir; ' . "\\\n"
  2417.          . "\t" . '    (cd $$subdir'
  2418.          . ' && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$('
  2419.          . (($relative_dir eq '.') ? 'distdir' : 'top_distdir')
  2420.          . ') distdir=../$(distdir)/$$subdir distdir) ' . "\\\n"
  2421.          . "\t" . '      || exit 1; ' . "\\\n"
  2422.          . "\t" . '  fi; ' . "\\\n"
  2423.          . "\tdone\n");
  2424.     }
  2425.  
  2426.     # If the target `dist-hook' exists, make sure it is run.  This
  2427.     # allows users to do random weird things to the distribution
  2428.     # before it is packaged up.
  2429.     push (@dist_targets, 'dist-hook') if &target_defined ('dist-hook');
  2430.  
  2431.     local ($targ);
  2432.     foreach $targ (@dist_targets)
  2433.     {
  2434.     # We must explicitly set distdir and top_distdir for these
  2435.     # sub-makes.
  2436.     $output_rules .= ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
  2437.               . " top_distdir=\"\$(top_distdir)\""
  2438.               . " distdir=\"\$(distdir)\" $targ\n");
  2439.     }
  2440.  
  2441.     push (@phony, 'distdir');
  2442. }
  2443.  
  2444. # Handle 'dist' target.
  2445. sub handle_dist
  2446. {
  2447.     local ($makefile) = @_;
  2448.  
  2449.     # Set up maint_charset.
  2450.     $local_maint_charset = &variable_value ('MAINT_CHARSET')
  2451.     if &variable_defined ('MAINT_CHARSET');
  2452.     $maint_charset = $local_maint_charset
  2453.     if $relative_dir eq '.';
  2454.  
  2455.     if (&variable_defined ('DIST_CHARSET'))
  2456.     {
  2457.     &am_line_error ('DIST_CHARSET',
  2458.             "DIST_CHARSET defined but no MAINT_CHARSET defined")
  2459.         if ! $local_maint_charset;
  2460.     if ($relative_dir eq '.')
  2461.     {
  2462.         $dist_charset = &variable_value ('DIST_CHARSET')
  2463.     }
  2464.     else
  2465.     {
  2466.         &am_line_error ('DIST_CHARSET',
  2467.                 "DIST_CHARSET can only be defined at top level");
  2468.     }
  2469.     }
  2470.  
  2471.     # Look for common files that should be included in distribution.
  2472.     local ($cfile);
  2473.     foreach $cfile (@common_files)
  2474.     {
  2475.     if (-f ($relative_dir . "/" . $cfile))
  2476.     {
  2477.         &push_dist_common ($cfile);
  2478.     }
  2479.     }
  2480.  
  2481.     # Always require configure.in and configure at top level, even if
  2482.     # they don't exist.  This is especially important for configure,
  2483.     # since it won't be created until autoconf is run -- which might
  2484.     # be after automake is run.
  2485.     &push_dist_common ('configure.in', 'configure')
  2486.     if $relative_dir eq '.';
  2487.  
  2488.     # Keys of %dist_common are names of files to distributed.  We put
  2489.     # README first because it then becomes easier to make a
  2490.     # Usenet-compliant shar file (in these, README must be first).
  2491.     # FIXME: do more ordering of files here.
  2492.     local (@coms);
  2493.     if (defined $dist_common{'README'})
  2494.     {
  2495.     push (@coms, 'README');
  2496.     delete $dist_common{'README'};
  2497.     }
  2498.     push (@coms, sort keys %dist_common);
  2499.  
  2500.     &define_pretty_variable ("DIST_COMMON", '', @coms);
  2501.     $output_vars .= "\n";
  2502.  
  2503.     # Some boilerplate.
  2504.     $output_vars .= &file_contents ('dist-vars') . "\n";
  2505.     &define_variable ('TAR', $TAR);
  2506.     &define_variable ('GZIP_ENV', '--best');
  2507.  
  2508.     # Put these things in rules section so it is easier for whoever
  2509.     # reads Makefile.in.
  2510.     if (! &variable_defined ('distdir'))
  2511.     {
  2512.     if ($relative_dir eq '.')
  2513.     {
  2514.         $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
  2515.     }
  2516.     else
  2517.     {
  2518.         $output_rules .= ("\n"
  2519.                   . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
  2520.                   . "\n");
  2521.     }
  2522.     }
  2523.     if ($relative_dir eq '.')
  2524.     {
  2525.     $output_rules .= "top_distdir = \$(distdir)\n\n";
  2526.     }
  2527.     else
  2528.     {
  2529.     $output_rules .= "\nsubdir = " . $relative_dir . "\n\n";
  2530.     }
  2531.  
  2532.     # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
  2533.     if ($relative_dir eq '.')
  2534.     {
  2535.     # Rule to check whether a distribution is viable.
  2536.     $output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
  2537. # it guarantees that the distribution is self-contained by making another
  2538. # tarfile.
  2539. distcheck: dist
  2540.     -rm -rf $(distdir)
  2541.     GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz
  2542.     mkdir $(distdir)/=build
  2543.     mkdir $(distdir)/=inst
  2544.     dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
  2545.               . (&target_defined ('distcheck-hook')
  2546.                  ? ("\t\$(MAKE) \$(AM_MAKEFLAGS)"
  2547.                 . " distcheck-hook")
  2548.                  : '')
  2549.               . '
  2550.     cd $(distdir)/=build \\
  2551.       && ../configure '
  2552.  
  2553.               . ($seen_gettext ? '--with-included-gettext ' : '')
  2554.               . '--srcdir=.. --prefix=$$dc_install_base \\
  2555.       && $(MAKE) $(AM_MAKEFLAGS) \\
  2556.       && $(MAKE) $(AM_MAKEFLAGS) dvi \\
  2557.       && $(MAKE) $(AM_MAKEFLAGS) check \\
  2558.       && $(MAKE) $(AM_MAKEFLAGS) install \\
  2559.       && $(MAKE) $(AM_MAKEFLAGS) installcheck \\
  2560.       && $(MAKE) $(AM_MAKEFLAGS) dist
  2561.     -rm -rf $(distdir)
  2562.     @banner="$(distdir).tar.gz is ready for distribution"; \\
  2563.     dashes=`echo "$$banner" | sed s/./=/g`; \\
  2564.     echo "$$dashes"; \\
  2565.     echo "$$banner"; \\
  2566.     echo "$$dashes"
  2567. ');
  2568.  
  2569.     local ($dist_all) = ('dist-all: distdir' . "\n"
  2570.                  . $dist_header);
  2571.     local ($curs);
  2572.     foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
  2573.     {
  2574.         if (defined $options{$curs} || $curs eq 'dist')
  2575.         {
  2576.         $output_rules .= ($curs . ': distdir' . "\n"
  2577.                   . $dist_header
  2578.                   . $dist{$curs}
  2579.                   . $dist_trailer);
  2580.         $dist_all .= $dist{$curs};
  2581.         }
  2582.     }
  2583.     $output_rules .= $dist_all . $dist_trailer;
  2584.     }
  2585.  
  2586.     # Generate distdir target.
  2587.     &handle_dist_worker ($makefile);
  2588. }
  2589.  
  2590. # Scan a single dependency file and rewrite the dependencies as
  2591. # appropriate.  Essentially this means:
  2592. # * Clean out absolute dependencies which are not desirable.
  2593. # * Rewrite other dependencies to be relative to $(top_srcdir).
  2594. sub scan_dependency_file
  2595. {
  2596.     local ($depfile) = @_;
  2597.  
  2598.     if (! open (DEP_FILE, $depfile))
  2599.     {
  2600.     &am_error ("couldn't open \`$depfile': $!");
  2601.     return;
  2602.     }
  2603.     print "automake: reading $depfile\n" if $verbose;
  2604.  
  2605.     # Sometimes it is necessary to omit some dependencies.
  2606.     local (%omit) = %omit_dependencies;
  2607.     if (&variable_defined ('OMIT_DEPENDENCIES'))
  2608.     {
  2609.     # FIXME: Doesn't work with conditionals.  I'm not sure if this
  2610.     # matters.
  2611.     grep ($omit{$_} = 1,
  2612.           &variable_value_as_list ('OMIT_DEPENDENCIES', ''));
  2613.     }
  2614.  
  2615.     local ($first_line) = 1;
  2616.     local ($last_line) = 0;
  2617.     local ($target, @dependencies);
  2618.     local ($one_dep, $xform);
  2619.     local ($just_file);
  2620.  
  2621.     local ($srcdir_rx, $fixup_rx);
  2622.     ($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
  2623.     =~ s/(\W)/\\$1/g;
  2624.     ($srcdir_rx = $srcdir_name . '/') =~ s/(\W)/\\$1/g;
  2625.  
  2626.     local ($rewrite_builddir) = (($top_builddir eq '.')
  2627.                  ? ''
  2628.                  : $top_builddir . '/');
  2629.  
  2630.     while (<DEP_FILE>)
  2631.     {
  2632.     last if $last_line;
  2633.     next if (/$WHITE_PATTERN/o);
  2634.     chop;
  2635.     if (! s/\\$//)
  2636.     {
  2637.         # No trailing "\" means this should be the last line of
  2638.         # the first target.  We can have multiple targets due to
  2639.         # the "deleted header file" fix.  For the generated
  2640.         # Makefile we simply skip these fake targets.
  2641.         $last_line = 1;
  2642.     }
  2643.  
  2644.     if ($first_line)
  2645.     {
  2646.         if (! /^([^:]+:)(.+)$/)
  2647.         {
  2648.           bad_format:
  2649.         &am_error ("\`$depfile' has incorrect format");
  2650.         close (DEP_FILE);
  2651.         return;
  2652.         }
  2653.  
  2654.         $_ = $2;
  2655.         # Make sure to strip the .P file from the target.
  2656.         ($target = $1) =~ s, *\.deps/[^.]+\.P,,;
  2657.  
  2658.         $first_line = 0;
  2659.     }
  2660.  
  2661.     foreach $one_dep (split (' ', $_))
  2662.     {
  2663.         ($just_file = $one_dep) =~ s,^.*/,,;
  2664.         next if defined $omit{$just_file};
  2665.  
  2666.         if ($one_dep =~ /^$fixup_rx/)
  2667.         {
  2668.         # The dependency points to the current directory in
  2669.         # some way.
  2670.         ($xform = $one_dep) =~ s/^$fixup_rx//;
  2671.         push (@dependencies, $xform);
  2672.         }
  2673.         elsif ($one_dep =~ /^$srcdir_rx/)
  2674.         {
  2675.         # The dependency is in some other directory in the package.
  2676.         ($xform = $one_dep) =~ s/^$srcdir_rx/$rewrite_builddir/;
  2677.         push (@dependencies, $xform);
  2678.         }
  2679.         elsif ($one_dep =~ /^\// || $one_dep =~ /^[A-Za-z]:\\/)
  2680.         {
  2681.         # Absolute path; ignore.
  2682.         }
  2683.         else
  2684.         {
  2685.         # Anything else is assumed to be correct.
  2686.         push (@dependencies, $one_dep);
  2687.         }
  2688.     }
  2689.     }
  2690.  
  2691.     &pretty_print_rule ($target, "\t", @dependencies);
  2692.  
  2693.     close (DEP_FILE);
  2694. }
  2695.  
  2696. # Handle auto-dependency code.
  2697. sub handle_dependencies
  2698. {
  2699.     # Make sure this variable is always marked as used.
  2700.     &examine_variable ('OMIT_DEPENDENCIES');
  2701.  
  2702.     if ($use_dependencies)
  2703.     {
  2704.     # Include GNU-make-specific auto-dep code.  Don't include it
  2705.     # if DEP_FILES would be empty.
  2706.     if (&saw_sources_p (0) && keys %dep_files)
  2707.     {
  2708.         &define_pretty_variable ('DEP_FILES', '', sort keys %dep_files);
  2709.         $output_rules .= &file_contents ('depend');
  2710.         push (@clean, 'depend');
  2711.         &push_phony_cleaners ('depend');
  2712.         # FIXME: this should use another property of the language
  2713.         # instead of being hard-coded.
  2714.         $output_rules .=
  2715.         &file_contents_with_transform ('s/\@EXT\@/.c/g;'
  2716.                            . 's/\@PFX\@//g;',
  2717.                            'depend2');
  2718.         local ($ext);
  2719.         foreach $ext (&objc_extensions)
  2720.         {
  2721.         $output_rules .=
  2722.             &file_contents_with_transform ('s/\@EXT\@/' . $ext . '/g;'
  2723.                            . 's/\@PFX\@/OBJC/g;',
  2724.                            'depend2');
  2725.         }
  2726.         foreach $ext (&cxx_extensions)
  2727.         {
  2728.         $output_rules .=
  2729.             &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
  2730.                            . 's/\@PFX\@/CXX/g;',
  2731.                            'depend2');
  2732.         }
  2733.     }
  2734.     }
  2735.     elsif ($build_directory ne '')
  2736.     {
  2737.     # Include any auto-generated deps that are present.  Note that
  2738.     # $build_directory ends in a "/".
  2739.     if (-d ($build_directory . $relative_dir . "/.deps"))
  2740.     {
  2741.         local ($depfile);
  2742.  
  2743.         foreach $depfile (&my_glob ($build_directory
  2744.                     . $relative_dir . "/.deps/*.P"))
  2745.         {
  2746.         &scan_dependency_file ($depfile);
  2747.         }
  2748.  
  2749.         $output_rules .= "\n";
  2750.     }
  2751.     }
  2752. }
  2753.  
  2754. # Handle subdirectories.
  2755. sub handle_subdirs
  2756. {
  2757.     return if ! &variable_defined ('SUBDIRS');
  2758.  
  2759.     # Make sure each directory mentioned in SUBDIRS actually exists.
  2760.     local ($dir);
  2761.     foreach $dir (&variable_value_as_list ('SUBDIRS', 'all'))
  2762.     {
  2763.     # Skip directories substituted by configure.
  2764.     next if $dir =~ /^\@.*\@$/;
  2765.  
  2766.     if (! -d $am_relative_dir . '/' . $dir)
  2767.     {
  2768.         &am_line_error ('SUBDIRS',
  2769.                 "required directory $am_relative_dir/$dir does not exist");
  2770.         next;
  2771.     }
  2772.  
  2773.     &am_line_error ('SUBDIRS', "directory should not contain \`/'")
  2774.         if $dir =~ /\//;
  2775.     }
  2776.  
  2777.     local ($xform) = ('s/\@INSTALLINFO\@/' .
  2778.               (defined $options{'no-installinfo'}
  2779.                ? 'install-info-recursive'
  2780.                : '')
  2781.               . '/;');
  2782.     $output_rules .= &file_contents_with_transform ($xform, 'subdirs');
  2783.  
  2784.     # Push a bunch of phony targets.
  2785.     local ($phonies);
  2786.     foreach $phonies ('-data', '-exec', 'dirs')
  2787.     {
  2788.     push (@phony, 'install' . $phonies . '-recursive');
  2789.     push (@phony, 'uninstall' . $phonies . '-recursive');
  2790.     }
  2791.     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
  2792.     {
  2793.     push (@phony, $phonies . '-recursive');
  2794.     }
  2795.     &push_phony_cleaners ('recursive');
  2796.  
  2797.     $recursive_install = 1;
  2798. }
  2799.  
  2800. # Handle aclocal.m4.
  2801. sub handle_aclocal_m4
  2802. {
  2803.     local ($regen_aclocal) = 0;
  2804.     if (-f 'aclocal.m4')
  2805.     {
  2806.     &define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
  2807.     &push_dist_common ('aclocal.m4');
  2808.  
  2809.     if (open (ACLOCAL, '< aclocal.m4'))
  2810.     {
  2811.         local ($line);
  2812.         $line = <ACLOCAL>;
  2813.         close (ACLOCAL);
  2814.  
  2815.         if ($line =~ 'generated automatically by aclocal')
  2816.         {
  2817.         $regen_aclocal = 1;
  2818.         }
  2819.     }
  2820.     }
  2821.  
  2822.     local ($acinclude) = 0;
  2823.     if (-f 'acinclude.m4')
  2824.     {
  2825.     $regen_aclocal = 1;
  2826.     $acinclude = 1;
  2827.     }
  2828.  
  2829.     # Note that it might be possible that aclocal.m4 doesn't exist but
  2830.     # should be auto-generated.  This case probably isn't very
  2831.     # important.
  2832.     if ($regen_aclocal)
  2833.     {
  2834.     local (@ac_deps) = (
  2835.                 ($seen_maint_mode
  2836.                  ? "\@MAINTAINER_MODE_TRUE\@"
  2837.                  : "") ,
  2838.                 "configure.in",
  2839.                 ($acinclude ? ' acinclude.m4' : '')
  2840.                 );
  2841.  
  2842.     # Scan all -I directories for m4 files.  These are our
  2843.     # dependencies.
  2844.     if (&variable_defined ('ACLOCAL_AMFLAGS'))
  2845.     {
  2846.         local ($examine_next, $amdir) = 0;
  2847.         foreach $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
  2848.         {
  2849.         if ($examine_next)
  2850.         {
  2851.             $examine_next = 0;
  2852.             if ($amdir !~ /^\// && -d $amdir)
  2853.             {
  2854.             push (@ac_deps, &my_glob ($amdir . '/*.m4'));
  2855.             }
  2856.         }
  2857.         elsif ($amdir eq '-I')
  2858.         {
  2859.             $examine_next = 1;
  2860.         }
  2861.         }
  2862.     }
  2863.  
  2864.     &pretty_print_rule ("\$(ACLOCAL_M4):", "\t\t", @ac_deps);
  2865.  
  2866.     $output_rules .=  ("\t"
  2867.                . 'cd $(srcdir) && $(ACLOCAL)'
  2868.                . (&variable_defined ('ACLOCAL_AMFLAGS')
  2869.                   ? ' $(ACLOCAL_AMFLAGS)' : '')
  2870.                . "\n");
  2871.     }
  2872. }
  2873.  
  2874. # Rewrite a list of input files into a form suitable to put on a
  2875. # dependency list.  The idea is that if an input file has a directory
  2876. # part the same as the current directory, then the directory part is
  2877. # simply removed.  But if the directory part is different, then
  2878. # $(top_srcdir) is prepended.  Among other things, this is used to
  2879. # generate the dependency list for the output files generated by
  2880. # AC_OUTPUT.  Consider what the dependencies should look like in this
  2881. # case:
  2882. #   AC_OUTPUT(src/out:src/in1:lib/in2)
  2883. # The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
  2884. # If 0 then files that require this addition will simply be ignored.
  2885. sub rewrite_inputs_into_dependencies
  2886. {
  2887.     local ($add_srcdir, @inputs) = @_;
  2888.     local ($single, @newinputs);
  2889.  
  2890.     foreach $single (@inputs)
  2891.     {
  2892.     if (&dirname ($single) eq $relative_dir)
  2893.     {
  2894.         push (@newinputs, &basename ($single));
  2895.     }
  2896.     elsif ($add_srcdir)
  2897.     {
  2898.         push (@newinputs, '$(top_srcdir)/' . $single);
  2899.     }
  2900.     }
  2901.  
  2902.     return @newinputs;
  2903. }
  2904.  
  2905. # Handle remaking and configure stuff.
  2906. # We need the name of the input file, to do proper remaking rules.
  2907. sub handle_configure
  2908. {
  2909.     local ($local, $input, @secondary_inputs) = @_;
  2910.  
  2911.     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
  2912.     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
  2913.     if &variable_defined ('SUBDIRS') && ! $seen_make_set;
  2914.  
  2915.     local ($top_reldir);
  2916.  
  2917.     local ($input_base) = &basename ($input);
  2918.     local ($local_base) = &basename ($local);
  2919.  
  2920.     local ($amfile) = $input_base . '.am';
  2921.     # We know we can always add '.in' because it really should be an
  2922.     # error if the .in was missing originally.
  2923.     local ($infile) = '$(srcdir)/' . $input_base . '.in';
  2924.     local ($colon_infile);
  2925.     if ($local ne $input || @secondary_inputs)
  2926.     {
  2927.     $colon_infile = ':' . $input . '.in';
  2928.     }
  2929.     $colon_infile .= ':' . join (':', @secondary_inputs)
  2930.     if @secondary_inputs;
  2931.  
  2932.     local (@rewritten) = &rewrite_inputs_into_dependencies (1,
  2933.                                 @secondary_inputs);
  2934.  
  2935.     # This rule remakes the Makefile.in.  Note use of
  2936.     # @MAINTAINER_MODE_TRUE@ forces us to abandon pretty-printing.
  2937.     # Sigh.
  2938.     $output_rules .= ($infile
  2939.               # NOTE perl 5.003 (with -w) gives a
  2940.               # uninitialized value error on the next line.
  2941.               # Don't know why.
  2942.               . ': '
  2943.               . ($seen_maint_mode ? "\@MAINTAINER_MODE_TRUE\@ " : '')
  2944.               . $amfile . ' '
  2945.               . '$(top_srcdir)/configure.in $(ACLOCAL_M4)'
  2946.                       . ' ' . join (' ', @include_stack)
  2947.                       . "\n"
  2948.               . "\tcd \$(top_srcdir) && \$(AUTOMAKE) "
  2949.               . ($cygnus_mode ? '--cygnus' : ('--' . $strictness_name))
  2950.               . ($cmdline_use_dependencies ? '' : ' --include-deps')
  2951.               . ' ' . $input . $colon_infile . "\n\n");
  2952.  
  2953.     # This rule remakes the Makefile.
  2954.     $output_rules .= ($local_base
  2955.               # NOTE: bogus uninit value error on next line;
  2956.               # see comment above.
  2957.               . ': '
  2958.               . $infile . ' '
  2959.               . join (' ', @rewritten)
  2960.               . ' $(top_builddir)/config.status'
  2961.               # NOTE: Makefile only depends on BUILT_SOURCES
  2962.               # when dependencies are being computed.  This is
  2963.               # a workaround for an obscure bug with
  2964.               # AC_LINK_FILES.  Anyway, when dependencies are
  2965.               # turned off, this shouldn't matter.
  2966.               . ($use_dependencies ? ' $(BUILT_SOURCES)' : '')
  2967.               . "\n"
  2968.               . "\tcd \$(top_builddir) \\\n"
  2969.               . "\t  && CONFIG_FILES="
  2970.               . (($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
  2971.               . $colon_infile
  2972.               . ' CONFIG_HEADERS= $(SHELL) ./config.status'
  2973.               . "\n\n");
  2974.  
  2975.     if ($relative_dir ne '.')
  2976.     {
  2977.     # In subdirectory.
  2978.     $top_reldir = '../';
  2979.     }
  2980.     else
  2981.     {
  2982.     &handle_aclocal_m4;
  2983.     $output_rules .= &file_contents ('remake');
  2984.     &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
  2985.     &examine_variable ('CONFIGURE_DEPENDENCIES');
  2986.     $top_reldir = '';
  2987.     }
  2988.  
  2989.     # Make it easy to see if there is a Makefile.am in a given
  2990.     # directory.
  2991.     local (%make_dirs, $iter);
  2992.     foreach $iter (@input_files)
  2993.     {
  2994.     $make_dirs{&dirname ($iter)} = 1;
  2995.     }
  2996.     # We also want to notice Makefile.in's.
  2997.     foreach $iter (@other_input_files)
  2998.     {
  2999.     if ($iter =~ /Makefile\.in$/)
  3000.     {
  3001.         $make_dirs{&dirname ($iter)} = 1;
  3002.     }
  3003.     }
  3004.  
  3005.     # If we have a configure header, require it.
  3006.     local ($one_hdr);
  3007.     local (@local_fullnames) = @config_fullnames;
  3008.     local (@local_names) = @config_names;
  3009.     local ($hdr_index) = 0;
  3010.     local ($distclean_config) = '';
  3011.     foreach $one_hdr (@config_headers)
  3012.     {
  3013.     local ($one_fullname) = shift (@local_fullnames);
  3014.     local ($one_name) = shift (@local_names);
  3015.     $hdr_index += 1;
  3016.     local ($header_dir) = &dirname ($one_name);
  3017.  
  3018.     # If the header is in the current directory we want to build
  3019.     # the header here.  Otherwise, if we're at the topmost
  3020.     # directory and the header's directory doesn't have a
  3021.     # Makefile, then we also want to build the header.
  3022.     if ($relative_dir eq $header_dir
  3023.         || ($relative_dir eq '.' && ! defined $make_dirs{$header_dir}))
  3024.     {
  3025.         local ($ch_sans_dir, $cn_sans_dir, $stamp_dir);
  3026.         if ($relative_dir eq $header_dir)
  3027.         {
  3028.         $cn_sans_dir = &basename ($one_name);
  3029.         $stamp_dir = '';
  3030.         }
  3031.         else
  3032.         {
  3033.         $cn_sans_dir = $one_name;
  3034.         if ($header_dir eq '.')
  3035.         {
  3036.             $stamp_dir = '';
  3037.         }
  3038.         else
  3039.         {
  3040.             $stamp_dir = $header_dir . '/';
  3041.         }
  3042.         }
  3043.  
  3044.         # Compute relative path from directory holding output
  3045.         # header to directory holding input header.  FIXME:
  3046.         # doesn't handle case where we have multiple inputs.
  3047.         if (&dirname ($one_hdr) eq $relative_dir)
  3048.         {
  3049.         $ch_sans_dir = &basename ($one_hdr);
  3050.         }
  3051.         else
  3052.         {
  3053.         local (@rel_out_path, $rel_path);
  3054.         # FIXME this chunk of code should be its own sub.
  3055.         # It is used elsewhere.
  3056.         foreach (split (/\//, $relative_dir))
  3057.         {
  3058.             next if $_ eq '' || $_ eq '.';
  3059.             if ($_ eq '..')
  3060.             {
  3061.             # FIXME: actually this is an error.
  3062.             pop @rel_out_path;
  3063.             }
  3064.             else
  3065.             {
  3066.             push (@rel_out_path, '..');
  3067.             }
  3068.         }
  3069.         if (@rel_out_path)
  3070.         {
  3071.             $ch_sans_dir = join ('/', @rel_out_path) . '/' . $one_hdr;
  3072.         }
  3073.         else
  3074.         {
  3075.             $ch_sans_dir = $one_hdr;
  3076.         }
  3077.         }
  3078.  
  3079.         &require_file_with_conf_line ($config_header_line,
  3080.                       $FOREIGN, $ch_sans_dir);
  3081.  
  3082.         # Header defined and in this directory.
  3083.         local (@files);
  3084.         if (-f $relative_dir . '/acconfig.h')
  3085.         {
  3086.         push (@files, 'acconfig.h');
  3087.         }
  3088.         if (-f $one_name . '.top')
  3089.         {
  3090.         push (@files, "${cn_sans_dir}.top");
  3091.         }
  3092.         if (-f $one_name . '.bot')
  3093.         {
  3094.         push (@files, "${cn_sans_dir}.bot");
  3095.         }
  3096.  
  3097.         &push_dist_common (@files);
  3098.  
  3099.         local ($stamp_name) = 'stamp-h';
  3100.         $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;
  3101.  
  3102.         local ($xform) = '';
  3103.  
  3104.         $xform = 's,\@FILES\@,' . join (' ', @files) . ',;';
  3105.         $xform .= 's,\@CONFIG_HEADER\@,' . "${cn_sans_dir}" . ',;';
  3106.         $xform .= 's,\@CONFIG_HEADER_IN\@,' . "${ch_sans_dir}" . ',;';
  3107.         $xform .= 's,\@CONFIG_HEADER_FULL\@,' . "${one_fullname}" . ',;';
  3108.         $xform .= 's,\@STAMP\@,' . "${stamp_dir}${stamp_name}" . ',;';
  3109.  
  3110.         $output_rules .= &file_contents_with_transform ($xform,
  3111.                                 'remake-hdr');
  3112.  
  3113.         local ($out_dir) = &dirname ($ch_sans_dir);
  3114.         &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
  3115.         &require_file_with_conf_line ($config_header_line, $FOREIGN,
  3116.                       "${out_dir}/${stamp_name}.in");
  3117.  
  3118.         $distclean_config .= ' ' if $distclean_config;
  3119.         $distclean_config .= $cn_sans_dir;
  3120.     }
  3121.     }
  3122.  
  3123.     if ($distclean_config)
  3124.     {
  3125.     $output_rules .= &file_contents_with_transform ('s,\@FILES\@,'
  3126.                             . $distclean_config
  3127.                             . ',;',
  3128.                             'clean-hdr');
  3129.     push (@clean, 'hdr');
  3130.     &push_phony_cleaners ('hdr');
  3131.     }
  3132.  
  3133.     # Set location of mkinstalldirs.
  3134.     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
  3135.     {
  3136.     &define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
  3137.                         . '/mkinstalldirs'));
  3138.     }
  3139.     else
  3140.     {
  3141.     &define_variable ('mkinstalldirs',
  3142.               '$(SHELL) $(top_srcdir)/mkinstalldirs');
  3143.     }
  3144.  
  3145.     &am_line_error ('CONFIG_HEADER',
  3146.             "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
  3147.     if &variable_defined ('CONFIG_HEADER');
  3148.  
  3149.     local ($one_name);
  3150.     local ($config_header) = '';
  3151.     foreach $one_name (@config_names)
  3152.     {
  3153.     # Generate CONFIG_HEADER define.
  3154.     local ($one_hdr);
  3155.     if ($relative_dir eq &dirname ($one_name))
  3156.     {
  3157.         $one_hdr = &basename ($one_name);
  3158.     }
  3159.     else
  3160.     {
  3161.         $one_hdr = "${top_builddir}/${one_name}";
  3162.     }
  3163.  
  3164.     $config_header .= ' ' if $config_header;
  3165.     $config_header .= $one_hdr;
  3166.     }
  3167.     if ($config_header)
  3168.     {
  3169.     &define_variable ("CONFIG_HEADER", $config_header);
  3170.     }
  3171.  
  3172.     # Now look for other files in this directory which must be remade
  3173.     # by config.status, and generate rules for them.
  3174.     local (@actual_other_files) = ();
  3175.     local ($file, $local);
  3176.     local (@inputs, @rewritten_inputs, $single);
  3177.     local ($need_rewritten);
  3178.     foreach $file (@other_input_files)
  3179.     {
  3180.     if ($file =~ /^([^:]*):(.*)$/)
  3181.     {
  3182.         # This is the ":" syntax of AC_OUTPUT.
  3183.         $file = $1;
  3184.         $local = &basename ($file);
  3185.         @inputs = split (':', $2);
  3186.         @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
  3187.         $need_rewritten = 1;
  3188.     }
  3189.     else
  3190.     {
  3191.         # Normal usage.
  3192.         $local = &basename ($file);
  3193.         @inputs = ($local . '.in');
  3194.         @rewritten_inputs =
  3195.         &rewrite_inputs_into_dependencies (1, $file . '.in');
  3196.         $need_rewritten = 0;
  3197.     }
  3198.  
  3199.     # Skip files not in this directory.
  3200.     next unless &dirname ($file) eq $relative_dir;
  3201.  
  3202.     # Skip any file that is an automake input.
  3203.     next if -f $file . '.am';
  3204.  
  3205.     # Some users have been tempted to put `stamp-h' in the
  3206.     # AC_OUTPUT line.  This won't do the right thing, so we
  3207.     # explicitly fail here.
  3208.     if ($local eq 'stamp-h')
  3209.     {
  3210.         # FIXME: allow real filename.
  3211.         &am_conf_error ('configure.in', $ac_output_line,
  3212.                 'stamp-h should not appear in AC_OUTPUT');
  3213.         next;
  3214.     }
  3215.  
  3216.     $output_rules .= ($local . ': '
  3217.               . '$(top_builddir)/config.status '
  3218.               . join (' ', @rewritten_inputs) . "\n"
  3219.               . "\t"
  3220.               . 'cd $(top_builddir) && CONFIG_FILES='
  3221.               . ($relative_dir eq '.' ? '' : '$(subdir)/')
  3222.                  . '$@' . ($need_rewritten
  3223.                     ? (':' . join (':', @inputs))
  3224.                     : '')
  3225.               . ' CONFIG_HEADERS= $(SHELL) ./config.status'
  3226.               . "\n");
  3227.     push_dist_common (@inputs);
  3228.     push (@actual_other_files, $local);
  3229.  
  3230.     # Require all input files.
  3231.     &require_file_with_conf_line ($ac_output_line, $FOREIGN,
  3232.                       &rewrite_inputs_into_dependencies (0, @inputs));
  3233.     }
  3234.  
  3235.     # These files get removed by "make clean".
  3236.     &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
  3237. }
  3238.  
  3239. # Handle C headers.
  3240. sub handle_headers
  3241. {
  3242.     local (@r);
  3243.     @r = &am_install_var ('header', 'HEADERS', 'include',
  3244.               'oldinclude', 'pkginclude',
  3245.               'noinst', 'check');
  3246.     foreach (@r)
  3247.     {
  3248.     next unless /\.(.*)$/;
  3249.     &saw_extension ($1);
  3250.     }
  3251. }
  3252.  
  3253. sub handle_gettext
  3254. {
  3255.     return if ! $seen_gettext || $relative_dir ne '.';
  3256.  
  3257.     if (! &variable_defined ('SUBDIRS'))
  3258.     {
  3259.     &am_conf_error
  3260.         ("AM_GNU_GETTEXT in configure.in but SUBDIRS not defined");
  3261.     return;
  3262.     }
  3263.  
  3264.     &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');
  3265.  
  3266.     if (&variable_defined ('SUBDIRS'))
  3267.     {
  3268.     &am_line_error
  3269.         ('SUBDIRS',
  3270.          "AM_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
  3271.         if $contents{'SUBDIRS'} !~ /\bpo\b/;
  3272.     &am_line_error
  3273.         ('SUBDIRS',
  3274.          "AM_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
  3275.         if $contents{'SUBDIRS'} !~ /\bintl\b/;
  3276.     }
  3277.  
  3278.     # Ensure that each language in ALL_LINGUAS has a .po file, and
  3279.     # each po file is mentioned in ALL_LINGUAS.
  3280.     if ($seen_linguas)
  3281.     {
  3282.     local (%linguas) = ();
  3283.     grep ($linguas{$_} = 1, split (' ', $all_linguas));
  3284.  
  3285.     foreach (<po/*.po>)
  3286.     {
  3287.         s/^po\///;
  3288.         s/\.po$//;
  3289.  
  3290.         &am_line_error ($all_linguas_line,
  3291.                 ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
  3292.         if ! $linguas{$_};
  3293.     }
  3294.  
  3295.     foreach (keys %linguas)
  3296.     {
  3297.         &am_line_error ($all_linguas_line,
  3298.                 "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
  3299.         if ! -f "po/$_.po";
  3300.     }
  3301.     }
  3302.     else
  3303.     {
  3304.     &am_error ("AM_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
  3305.     }
  3306. }
  3307.  
  3308. # Handle footer elements.
  3309. sub handle_footer
  3310. {
  3311.     if ($contents{'SOURCES'})
  3312.     {
  3313.     # NOTE don't use define_pretty_variable here, because
  3314.     # $contents{...} is already defined.
  3315.     $output_vars .= 'SOURCES = ' . $contents{'SOURCES'} . "\n";
  3316.     }
  3317.     if ($contents{'OBJECTS'})
  3318.     {
  3319.     # NOTE don't use define_pretty_variable here, because
  3320.     # $contents{...} is already defined.
  3321.     $output_vars .= 'OBJECTS = ' . $contents{'OBJECTS'} . "\n";
  3322.     }
  3323.     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
  3324.     {
  3325.     $output_vars .= "\n";
  3326.     }
  3327.  
  3328.     if (&variable_defined ('SUFFIXES'))
  3329.     {
  3330.     # Push actual suffixes, and not $(SUFFIXES).  Some versions of
  3331.     # make do not like variable substitutions on the .SUFFIXES
  3332.     # line.
  3333.     push (@suffixes, &variable_value_as_list ('SUFFIXES', ''));
  3334.     }
  3335.     if (&target_defined ('.SUFFIXES'))
  3336.     {
  3337.     &am_line_error ('.SUFFIXES',
  3338.             "use variable \`SUFFIXES', not target \`.SUFFIXES'");
  3339.     }
  3340.  
  3341.     # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
  3342.     # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
  3343.     # anything else, by sticking it right after the default: target.
  3344.     $output_header .= ".SUFFIXES:\n";
  3345.     if (@suffixes)
  3346.     {
  3347.  
  3348.     # Make sure suffixes has unique elements.  Sort them to ensure
  3349.     # the output remains consistent.
  3350.     local (%suffixes);
  3351.  
  3352.     grep ($suffixes{$_} = 1, @suffixes);
  3353.  
  3354.     $output_header .= (".SUFFIXES: "
  3355.                . join (' ', sort keys %suffixes)
  3356.                . "\n");
  3357.     }
  3358.     $output_trailer .= &file_contents ('footer');
  3359. }
  3360.  
  3361. # Deal with installdirs target.
  3362. sub handle_installdirs
  3363. {
  3364.     # GNU Makefile standards recommend this.
  3365.     if ($recursive_install)
  3366.     {
  3367.     # We create a separate `-am' target so that the -recursive
  3368.     # rule will work correctly.
  3369.     $output_rules .= ("installdirs: installdirs-recursive\n"
  3370.               . "installdirs-am:\n");
  3371.     push (@phony, 'installdirs-am');
  3372.     }
  3373.     else
  3374.     {
  3375.     $output_rules .= "installdirs:\n";
  3376.     }
  3377.     push (@phony, 'installdirs');
  3378.     if (@installdirs)
  3379.     {
  3380.     &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
  3381.                 @installdirs);
  3382.     }
  3383.     $output_rules .= "\n";
  3384. }
  3385.  
  3386. # There are several targets which need to be merged.  This is because
  3387. # their complete definition is compiled from many parts.  Note that we
  3388. # avoid double colon rules, otherwise we'd use them instead.
  3389. sub handle_merge_targets
  3390. {
  3391.     local ($makefile) = @_;
  3392.  
  3393.     # There are a few install-related variables that you should not define.
  3394.     local ($var);
  3395.     foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
  3396.     {
  3397.     if (&variable_defined ($var))
  3398.     {
  3399.         &am_line_error ($var, "\`$var' should not be defined");
  3400.     }
  3401.     }
  3402.  
  3403.     # Put this at the beginning for the sake of non-GNU makes.  This
  3404.     # is still wrong if these makes can run parallel jobs.  But it is
  3405.     # right enough.
  3406.     unshift (@all, &basename ($makefile));
  3407.  
  3408.     local ($one_name);
  3409.     foreach $one_name (@config_names)
  3410.     {
  3411.     push (@all, &basename ($one_name))
  3412.         if &dirname ($one_name) eq $relative_dir;
  3413.     }
  3414.  
  3415.     &do_one_merge_target ('info', @info);
  3416.     &do_one_merge_target ('dvi', @dvi);
  3417.     &do_check_merge_target;
  3418.     &do_one_merge_target ('installcheck', @installcheck);
  3419.  
  3420.     if (defined $options{'no-installinfo'})
  3421.     {
  3422.     &do_one_merge_target ('install-info', '');
  3423.     }
  3424.     elsif (&target_defined ('install-info-local'))
  3425.     {
  3426.     &am_line_error ('install-info-local',
  3427.             "\`install-info-local' target defined but \`no-installinfo' option not in use");
  3428.     }
  3429.  
  3430.     local ($utarg);
  3431.     foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
  3432.             'uninstall-exec-local', 'uninstall-exec-hook')
  3433.     {
  3434.     if (&target_defined ($utarg))
  3435.     {
  3436.         local ($x);
  3437.         ($x = $utarg) =~ s/(data|exec)-//;
  3438.         &am_line_error ($utarg, "use \`$x', not \`$utarg'");
  3439.     }
  3440.     }
  3441.  
  3442.     if (&target_defined ('install-local'))
  3443.     {
  3444.     &am_line_error ('install-local',
  3445.             "use \`install-data-local' or \`install-exec-local', not \`install-local'");
  3446.     }
  3447.  
  3448.     if (@all)
  3449.     {
  3450.     local ($one_name);
  3451.     local ($local_headers) = '';
  3452.     foreach $one_name (@config_names)
  3453.     {
  3454.         if (&dirname ($one_name) eq $relative_dir)
  3455.         {
  3456.         $local_headers .= ' ' if $local_headers;
  3457.         $local_headers .= &basename ($one_name);
  3458.         }
  3459.     }
  3460.     if ($local_headers)
  3461.     {
  3462.         # This is kind of a hack, but I couldn't see a better way
  3463.         # to handle it.  In this particular case, we need to make
  3464.         # sure config.h is built before we recurse.  We can't do
  3465.         # this by changing the order of dependencies to the "all"
  3466.         # because that breaks when using parallel makes.  Instead
  3467.         # we handle things explicitly.
  3468.         $output_rules .= ("all-recursive-am: ${local_headers}"
  3469.                   . "\n\t"
  3470.                   . '$(MAKE) $(AM_MAKEFLAGS)'
  3471.                   . " all-recursive"
  3472.                   . "\n\n");
  3473.         $all_target = 'all-recursive-am';
  3474.         push (@phony, 'all-recursive-am');
  3475.     }
  3476.     }
  3477.  
  3478.     # Print definitions users can use.
  3479.     &do_one_merge_target ('install-exec', @install_exec);
  3480.     $output_rules .= "\n";
  3481.  
  3482.     &do_one_merge_target ('install-data', @install_data);
  3483.     $output_rules .= "\n";
  3484.  
  3485.     &do_one_merge_target ('install', 'all-am');
  3486.     &do_one_merge_target ('uninstall', @uninstall);
  3487.  
  3488.     &do_one_merge_target ('all', @all);
  3489.  
  3490.     # Generate the new 'install-strip' target.  We can't just set
  3491.     # INSTALL_PROGRAM because that might be a relative path.
  3492.     $output_rules .= ("install-strip:\n\t"
  3493.               . '$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install'
  3494.               . "\n");
  3495. }
  3496.  
  3497. # Helper for handle_merge_targets.  Note that handle_merge_targets
  3498. # relies on the fact that this doesn't add an extra \n at the end.
  3499. sub do_one_merge_target
  3500. {
  3501.     local ($name, @values) = @_;
  3502.  
  3503.     if (&target_defined ($name . '-local'))
  3504.     {
  3505.     # User defined local form of target.  So include it.
  3506.     push (@values, $name . '-local');
  3507.     push (@phony, $name . '-local');
  3508.     }
  3509.  
  3510.     &pretty_print_rule ($name . "-am:", "\t\t", @values);
  3511.     if ($name eq 'install')
  3512.     {
  3513.     # Special-case `install-am' to run install-exec-am and
  3514.     # install-data-am after all-am is built.
  3515.     &pretty_print_rule ("\t\@\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
  3516.                 'install-exec-am', 'install-data-am');
  3517.     }
  3518.     elsif ($name eq 'install-exec' && &target_defined ('install-exec-hook'))
  3519.     {
  3520.     $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
  3521.               . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-exec-hook'
  3522.               . "\n");
  3523.     }
  3524.     elsif ($name eq 'install-data' && &target_defined ('install-data-hook'))
  3525.     {
  3526.     $output_rules .= ("\t\@\$(NORMAL_INSTALL)\n"
  3527.               . "\t" . '$(MAKE) $(AM_MAKEFLAGS) install-data-hook'
  3528.               . "\n");
  3529.     }
  3530.  
  3531.     local ($lname) = $name . ($recursive_install ? '-recursive' : '-am');
  3532.     local ($tname) = $name;
  3533.     # To understand this special case, see handle_merge_targets.
  3534.     if ($name eq 'all')
  3535.     {
  3536.     $tname = 'all-redirect';
  3537.     $lname = $all_target if $recursive_install;
  3538.     push (@phony, 'all-redirect');
  3539.     $output_all = "all: all-redirect\n";
  3540.     }
  3541.     &pretty_print_rule ($tname . ":", "\t\t", $lname);
  3542.     push (@phony, $name . '-am', $name);
  3543. }
  3544.  
  3545. # Handle check merge target specially.
  3546. sub do_check_merge_target
  3547. {
  3548.     if (&target_defined ('check-local'))
  3549.     {
  3550.     # User defined local form of target.  So include it.
  3551.     push (@check_tests, 'check-local');
  3552.     push (@phony, 'check-local');
  3553.     }
  3554.  
  3555.     # In --cygnus mode, check doesn't depend on all.
  3556.     if ($cygnus_mode)
  3557.     {
  3558.     # Just run the local check rules.
  3559.     &pretty_print_rule ('check-am:', "\t\t", @check);
  3560.     }
  3561.     else
  3562.     {
  3563.     # The check target must depend on the local equivalent of
  3564.     # `all', to ensure all the primary targets are built.  Then it
  3565.     # must build the local check rules.
  3566.     $output_rules .= "check-am: all-am\n";
  3567.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
  3568.                 @check)
  3569.         if @check;
  3570.     }
  3571.     &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
  3572.             @check_tests)
  3573.     if @check_tests;
  3574.  
  3575.     push (@phony, 'check', 'check-am');
  3576.     $output_rules .= ("check: "
  3577.               . ($recursive_install ? 'check-recursive' : 'check-am')
  3578.               . "\n");
  3579. }
  3580.  
  3581. # Handle all 'clean' targets.
  3582. sub handle_clean
  3583. {
  3584.     local ($xform) = '';
  3585.     local ($name);
  3586.  
  3587.     # Don't include `MAINTAINER'; it is handled specially below.
  3588.     foreach $name ('MOSTLY', '', 'DIST')
  3589.     {
  3590.     if (! &variable_defined ($name . 'CLEANFILES'))
  3591.     {
  3592.         $xform .= 's/^' . $name . 'CLEAN.*$//;';
  3593.     }
  3594.     else
  3595.     {
  3596.         $xform .= 's/^' . $name . 'CLEAN//;';
  3597.     }
  3598.     }
  3599.  
  3600.     # Built sources are automatically removed by maintainer-clean.
  3601.     push (@maintainer_clean_files, '\$(BUILT_SOURCES)')
  3602.     if &variable_defined ('BUILT_SOURCES');
  3603.     push (@maintainer_clean_files, '\$(MAINTAINERCLEANFILES)')
  3604.     if &variable_defined ('MAINTAINERCLEANFILES');
  3605.     if (! @maintainer_clean_files)
  3606.     {
  3607.     $xform .= 's/^MAINTAINERCLEAN.*$//;';
  3608.     }
  3609.     else
  3610.     {
  3611.     $xform .= ('s/^MAINTAINERCLEAN//;'
  3612.            # Join with no space to avoid spurious `test -z'
  3613.            # success at runtime.
  3614.            . 's,\@MCFILES\@,' . join ('', @maintainer_clean_files)
  3615.            . ',;'
  3616.            # A space is required in the join here.
  3617.            . 's,\@MFILES\@,' . join (' ', @maintainer_clean_files)
  3618.            . ',;');
  3619.     }
  3620.  
  3621.     $output_rules .= &file_contents_with_transform ($xform, 'clean');
  3622.  
  3623.     push (@clean, 'generic');
  3624.     &push_phony_cleaners ('generic');
  3625.  
  3626.     &do_one_clean_target ('clean', 'mostly', '', @clean);
  3627.     &do_one_clean_target ('clean', '', 'mostly', @clean);
  3628.     &do_one_clean_target ('clean', 'dist', '', @clean);
  3629.     &do_one_clean_target ('clean', 'maintainer-', 'dist', @clean);
  3630.  
  3631.     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
  3632. }
  3633.  
  3634. # Helper for handle_clean.
  3635. sub do_one_clean_target
  3636. {
  3637.     local ($target, $name, $last_name, @deps) = @_;
  3638.  
  3639.     # Change each dependency `BLARG' into `clean-BLARG'.
  3640.     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
  3641.  
  3642.     # Push the previous clean target.  There is no previous clean
  3643.     # target if we're doing mostlyclean.
  3644.     push (@deps, $last_name . $target . '-am')
  3645.     unless $name eq 'mostly';
  3646.  
  3647.     # If a -local version of the rule is given, add it to the list.
  3648.     if (&target_defined ($name . $target . '-local'))
  3649.     {
  3650.     push (@deps, $name . $target . '-local');
  3651.     }
  3652.  
  3653.     # Print the target and the dependencies.
  3654.     &pretty_print_rule ($name . $target . "-am: ", "\t\t", @deps);
  3655.  
  3656.     # FIXME: shouldn't we really print these messages before running
  3657.     # the dependencies?
  3658.     if ($name . $target eq 'maintainer-clean')
  3659.     {
  3660.     # Print a special warning.
  3661.     $output_rules .=
  3662.         ("\t\@echo \"This command is intended for maintainers to use;\"\n"
  3663.          . "\t\@echo \"it deletes files that may require special "
  3664.          . "tools to rebuild.\"\n");
  3665.     }
  3666.     elsif ($name . $target eq 'distclean')
  3667.     {
  3668.     $output_rules .= "\t-rm -f libtool\n" if $seen_libtool;
  3669.     }
  3670.     $output_rules .= "\n";
  3671.  
  3672.     # Now generate the actual clean target.
  3673.     $output_rules .= ($name . $target . ": " . $name . $target
  3674.               . ($recursive_install ? '-recursive' : '-am')
  3675.               . "\n");
  3676.  
  3677.     # We special-case config.status here.  If we do it as part of the
  3678.     # normal clean processing for this directory, then it might be
  3679.     # removed before some subdir is cleaned.  However, that subdir's
  3680.     # Makefile depends on config.status.
  3681.     if (($name . $target eq 'maintainer-clean'
  3682.      || $name . $target eq 'distclean')
  3683.     && $relative_dir eq '.')
  3684.     {
  3685.     $output_rules .= "\t-rm -f config.status\n";
  3686.     }
  3687.     $output_rules .= "\n";
  3688. }
  3689.  
  3690. # Handle .PHONY target.
  3691. sub handle_phony
  3692. {
  3693.     &pretty_print_rule ('.PHONY:', "", @phony);
  3694.     $output_rules .= "\n";
  3695. }
  3696.  
  3697. # Handle TESTS variable and other checks.
  3698. sub handle_tests
  3699. {
  3700.     if (defined $options{'dejagnu'})
  3701.     {
  3702.     push (@check_tests, 'check-DEJAGNU');
  3703.     push (@phony, 'check-DEJAGNU');
  3704.  
  3705.     local ($xform);
  3706.     if ($cygnus_mode)
  3707.     {
  3708.         $xform = 's/^CYGNUS//;';
  3709.     }
  3710.     else
  3711.     {
  3712.         $xform = 's/^CYGNUS.*$//;';
  3713.     }
  3714.     $output_rules .= &file_contents_with_transform ($xform, 'dejagnu');
  3715.  
  3716.     # In Cygnus mode, these are found in the build tree.
  3717.     # Otherwise they are looked for in $PATH.
  3718.     &define_program_variable ('EXPECT', 'build', 'expect', 'expect');
  3719.     &define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');
  3720.  
  3721.     # Only create site.exp rule if user hasn't already written
  3722.     # one.
  3723.     if (! &target_defined ('site.exp'))
  3724.     {
  3725.         # Note that in the rule we don't directly generate
  3726.         # site.exp to avoid the possibility of a corrupted
  3727.         # site.exp if make is interrupted.  Jim Meyering has some
  3728.         # useful text on this topic.
  3729.         $output_rules .= ("site.exp: Makefile\n"
  3730.                   . "\t\@echo 'Making a new site.exp file...'\n"
  3731.                   . "\t\@test ! -f site.bak || rm -f site.bak\n"
  3732.                   . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
  3733.                   . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
  3734.                   . "\t\@echo '# edit the last section' >> \$\@-t\n"
  3735.                   . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
  3736.                   . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
  3737.                   . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");
  3738.  
  3739.         # Extra stuff for AC_CANONICAL_*
  3740.         local (@whatlist) = ();
  3741.         if ($seen_canonical)
  3742.         {
  3743.         push (@whatlist, 'host');
  3744.         }
  3745.  
  3746.         # Extra stuff only for AC_CANONICAL_SYSTEM.
  3747.         if ($seen_canonical == $AC_CANONICAL_SYSTEM)
  3748.         {
  3749.         push (@whatlist, 'target', 'build');
  3750.         }
  3751.  
  3752.         local ($c1, $c2);
  3753.         foreach $c1 (@whatlist)
  3754.         {
  3755.         foreach $c2 ('alias', 'triplet')
  3756.         {
  3757.             $output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
  3758.         }
  3759.         }
  3760.  
  3761.         $output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
  3762.                   . "\t\@test ! -f site.exp || sed '1,/^## All variables above are.*##/ d' site.exp >> \$\@-t\n"
  3763.                   . "\t\@test ! -f site.exp || mv site.exp site.bak\n"
  3764.                   . "\t\@mv \$\@-t site.exp\n");
  3765.     }
  3766.     }
  3767.     else
  3768.     {
  3769.     local ($c);
  3770.     foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
  3771.     {
  3772.         if (&variable_defined ($c))
  3773.         {
  3774.         &am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
  3775.         }
  3776.     }
  3777.     }
  3778.  
  3779.     if (&variable_defined ('TESTS'))
  3780.     {
  3781.     push (@check_tests, 'check-TESTS');
  3782.     push (@phony, 'check-TESTS');
  3783.  
  3784.     $output_rules .= 'check-TESTS: $(TESTS)
  3785.     @failed=0; all=0; \\
  3786.     srcdir=$(srcdir); export srcdir; \\
  3787.     for tst in $(TESTS); do \\
  3788.       if test -f $$tst; then dir=.; \\
  3789.       else dir="$(srcdir)"; fi; \\
  3790.       if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
  3791.         all=`expr $$all + 1`; \\
  3792.         echo "PASS: $$tst"; \\
  3793.       elif test $$? -ne 77; then \\
  3794.         all=`expr $$all + 1`; \\
  3795.         failed=`expr $$failed + 1`; \\
  3796.         echo "FAIL: $$tst"; \\
  3797.       fi; \\
  3798.     done; \\
  3799.     if test "$$failed" -eq 0; then \\
  3800.       banner="All $$all tests passed"; \\
  3801.     else \\
  3802.       banner="$$failed of $$all tests failed"; \\
  3803.     fi; \\
  3804.     dashes=`echo "$$banner" | sed s/./=/g`; \\
  3805.     echo "$$dashes"; \\
  3806.     echo "$$banner"; \\
  3807.     echo "$$dashes"; \\
  3808.     test "$$failed" -eq 0
  3809. ';
  3810.     }
  3811. }
  3812.  
  3813. # Handle Emacs Lisp.
  3814. sub handle_emacs_lisp
  3815. {
  3816.     local (@elfiles) = &am_install_var ('lisp', 'LISP', 'lisp', 'noinst');
  3817.  
  3818.     if (@elfiles)
  3819.     {
  3820.     # Found some lisp.
  3821.     &define_configure_variable ('lispdir');
  3822.     &define_configure_variable ('EMACS');
  3823.     $output_rules .= (".el.elc:\n"
  3824.               . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
  3825.               . "\tif test \$(EMACS) != no; then \\\n"
  3826.               . "\t  EMACS=\$(EMACS) \$(SHELL) \$(srcdir)/elisp-comp \$<; \\\n"
  3827.               . "\tfi\n");
  3828.     push (@suffixes, '.el', '.elc');
  3829.  
  3830.     # Generate .elc files.
  3831.     grep ($_ .= 'c', @elfiles);
  3832.     &define_pretty_variable ('ELCFILES', '', @elfiles);
  3833.  
  3834.     $output_rules .= &file_contents ('lisp-clean');
  3835.     push (@clean, 'lisp');
  3836.     &push_phony_cleaners ('lisp');
  3837.  
  3838.     push (@all, '$(ELCFILES)');
  3839.  
  3840.     local ($varname);
  3841.     if (&variable_defined ('lisp_LISP'))
  3842.     {
  3843.         $varname = 'lisp_LISP';
  3844.         &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
  3845.         if ! $seen_lispdir;
  3846.     }
  3847.     else
  3848.     {
  3849.         $varname = 'noinst_LISP';
  3850.     }
  3851.  
  3852.     &require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
  3853.     }
  3854. }
  3855.  
  3856. # Handle Java.
  3857. sub handle_java
  3858. {
  3859.     local (@sourcelist) = &am_install_var ('-clean', 'java', 'JAVA',
  3860.                        'java', 'noinst', 'check');
  3861.     return if ! @sourcelist;
  3862.  
  3863.     &define_variable ('JAVAC', 'javac');
  3864.     &define_variable ('JAVACFLAGS', '');
  3865.     &define_variable ('CLASSPATH_ENV',
  3866.               'CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH');
  3867.     &define_variable ('JAVAROOT', '$(top_builddir)');
  3868.  
  3869.     local (%valid) = &am_primary_prefixes ('JAVA', 'java', 'noinst', 'check');
  3870.  
  3871.     local ($dir, $curs);
  3872.     foreach $curs (keys %valid)
  3873.     {
  3874.     if (! &variable_defined ($curs . '_JAVA') || $curs eq 'noinst'
  3875.         || $curs eq 'EXTRA')
  3876.     {
  3877.         next;
  3878.     }
  3879.  
  3880.     if (defined $dir)
  3881.     {
  3882.         &am_line_error ($curs . '_JAVA',
  3883.                 "multiple _JAVA primaries in use");
  3884.     }
  3885.     $dir = $curs;
  3886.     }
  3887.  
  3888.     $output_rules .= ('class' . $dir . '.stamp: $(' . $dir . '_JAVA)' . "\n"
  3889.               . "\t" . '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) '
  3890.               . '$(JAVACFLAGS) $?' . "\n"
  3891.               . "\t" . 'echo timestamp > class' . $dir . '.stamp'
  3892.               . "\n");
  3893.     push (@all, 'class' . $dir . '.stamp');
  3894.     &push_dist_common ('$(' . $dir . '_JAVA)');
  3895. }
  3896.  
  3897. # Handle some of the minor options.
  3898. sub handle_minor_options
  3899. {
  3900.     if (defined $options{'readme-alpha'})
  3901.     {
  3902.     if ($relative_dir eq '.')
  3903.     {
  3904.         if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
  3905.         {
  3906.         # FIXME: allow real filename.
  3907.         &am_conf_line_error ('configure.in',
  3908.                      $package_version_line,
  3909.                      "version \`$package_version' doesn't follow Gnits standards");
  3910.         }
  3911.         elsif (defined $1 && -f 'README-alpha')
  3912.         {
  3913.         # This means we have an alpha release.  See
  3914.         # GNITS_VERSION_PATTERN for details.
  3915.         &require_file ($FOREIGN, 'README-alpha');
  3916.         }
  3917.     }
  3918.     }
  3919. }
  3920.  
  3921. ################################################################
  3922.  
  3923. # Scan one file for interesting things.  Subroutine of scan_configure.
  3924. sub scan_one_configure_file
  3925. {
  3926.     local ($filename) = @_;
  3927.     local (*CONFIGURE);
  3928.  
  3929.     open (CONFIGURE, $filename)
  3930.     || die "automake: couldn't open \`$filename': $!\n";
  3931.     print "automake: reading $filename\n" if $verbose;
  3932.  
  3933.     while (<CONFIGURE>)
  3934.     {
  3935.     # Remove comments from current line.
  3936.     s/\bdnl\b.*$//;
  3937.     s/\#.*$//;
  3938.  
  3939.     # Skip macro definitions.  Otherwise we might be confused into
  3940.     # thinking that a macro that was only defined was actually
  3941.     # used.
  3942.     next if /AC_DEFUN/;
  3943.  
  3944.     # Follow includes.  This is a weirdness commonly in use at
  3945.     # Cygnus and hopefully nowhere else.
  3946.     if (/sinclude\((.*)\)/ && -f $1)
  3947.     {
  3948.         &scan_one_configure_file ($1);
  3949.     }
  3950.  
  3951.     # Populate libobjs array.
  3952.     if (/AC_FUNC_ALLOCA/)
  3953.     {
  3954.         $libsources{'alloca.c'} = 1;
  3955.     }
  3956.     elsif (/AC_FUNC_GETLOADAVG/)
  3957.     {
  3958.         $libsources{'getloadavg.c'} = 1;
  3959.     }
  3960.     elsif (/AC_FUNC_MEMCMP/)
  3961.     {
  3962.         $libsources{'memcmp.c'} = 1;
  3963.     }
  3964.     elsif (/AC_STRUCT_ST_BLOCKS/)
  3965.     {
  3966.         $libsources{'fileblocks.c'} = 1;
  3967.     }
  3968.     elsif (/A[CM]_REPLACE_GNU_GETOPT/)
  3969.     {
  3970.         $libsources{'getopt.c'} = 1;
  3971.         $libsources{'getopt1.c'} = 1;
  3972.     }
  3973.     elsif (/AM_FUNC_STRTOD/)
  3974.     {
  3975.         $libsources{'strtod.c'} = 1;
  3976.     }
  3977.     elsif (/AM_WITH_REGEX/)
  3978.     {
  3979.         $libsources{'rx.c'} = 1;
  3980.         $libsources{'rx.h'} = 1;
  3981.         $libsources{'regex.c'} = 1;
  3982.         $libsources{'regex.h'} = 1;
  3983.         $omit_dependencies{'rx.h'} = 1;
  3984.         $omit_dependencies{'regex.h'} = 1;
  3985.     }
  3986.     elsif (/AM_FUNC_MKTIME/)
  3987.     {
  3988.         $libsources{'mktime.c'} = 1;
  3989.     }
  3990.     elsif (/AM_FUNC_ERROR_AT_LINE/)
  3991.     {
  3992.         $libsources{'error.c'} = 1;
  3993.         $libsources{'error.h'} = 1;
  3994.     }
  3995.     elsif (/AM_FUNC_OBSTACK/)
  3996.     {
  3997.         $libsources{'obstack.c'} = 1;
  3998.         $libsources{'obstack.h'} = 1;
  3999.     }
  4000.     elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
  4001.            || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
  4002.     {
  4003.         foreach $libobj_iter (split (' ', $1))
  4004.         {
  4005.         if ($libobj_iter =~ /^(.*)\.o(bj)?$/)
  4006.         {
  4007.             $libsources{$1 . '.c'} = 1;
  4008.         }
  4009.         }
  4010.     }
  4011.  
  4012.     if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
  4013.     {
  4014.         $in_ac_replace = 1;
  4015.     }
  4016.     if ($in_ac_replace)
  4017.     {
  4018.         $in_ac_replace = 0 if s/[\]\)].*$//;
  4019.         # Remove trailing backslash.
  4020.         s/\\$//;
  4021.         foreach (split)
  4022.         {
  4023.         # Need to skip empty elements for Perl 4.
  4024.         next if $_ eq '';
  4025.         $libsources{$_ . '.c'} = 1;
  4026.         }
  4027.     }
  4028.  
  4029.     if (/$obsolete_rx/o)
  4030.     {
  4031.         local ($hint) = '';
  4032.         if ($obsolete_macros{$1})
  4033.         {
  4034.         $hint = '; ' . $obsolete_macros{$1};
  4035.         }
  4036.         &am_conf_line_error ($filename, $., "\`$1' is obsolete$hint");
  4037.     }
  4038.  
  4039.     # Process the AC_OUTPUT macro.
  4040.     if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
  4041.     {
  4042.         $in_ac_output = 1;
  4043.         $ac_output_line = $.;
  4044.     }
  4045.     if ($in_ac_output)
  4046.     {
  4047.         local ($closing) = 0;
  4048.         if (s/[\]\),].*$//)
  4049.         {
  4050.         $in_ac_output = 0;
  4051.         $closing = 1;
  4052.         }
  4053.  
  4054.         # Look at potential Makefile.am's.
  4055.         foreach (split)
  4056.         {
  4057.         # Must skip empty string for Perl 4.
  4058.         next if $_ eq "\\" || $_ eq '';
  4059.  
  4060.         # Handle $local:$input syntax.  Note that we ignore
  4061.         # every input file past the first, though we keep
  4062.         # those around for later.
  4063.         local ($local, $input, @rest) = split (/:/);
  4064.         if (! $input)
  4065.         {
  4066.             $input = $local;
  4067.         }
  4068.         else
  4069.         {
  4070.             # FIXME: should be error if .in is missing.
  4071.             $input =~ s/\.in$//;
  4072.         }
  4073.  
  4074.         if (-f $input . '.am')
  4075.         {
  4076.             # We have a file that automake should generate.
  4077.             push (@make_input_list, $input);
  4078.             $make_list{$input} = join (':', ($local, @rest));
  4079.         }
  4080.         else
  4081.         {
  4082.             # We have a file that automake should cause to be
  4083.             # rebuilt, but shouldn't generate itself.
  4084.             push (@other_input_files, $_);
  4085.         }
  4086.         }
  4087.  
  4088.         if ($closing && @make_input_list == 0 && @other_input_files == 0)
  4089.         {
  4090.         &am_conf_line_error ($filename, $ac_output_line,
  4091.                      "No files mentioned in \`AC_OUTPUT'");
  4092.         exit 1;
  4093.         }
  4094.     }
  4095.  
  4096.     if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
  4097.     {
  4098.         @config_aux_path = $1;
  4099.     }
  4100.  
  4101.     # Check for ansi2knr.
  4102.     $am_c_prototypes = 1 if /AM_C_PROTOTYPES/;
  4103.  
  4104.     # Check for exe extension stuff.
  4105.     if (/AC_EXEEXT/)
  4106.     {
  4107.         $seen_exeext = 1;
  4108.         $configure_vars{'EXEEXT'} = $filename . ':' . $.;
  4109.     }
  4110.  
  4111.     if (/AC_OBJEXT/)
  4112.     {
  4113.         $seen_objext = 1;
  4114.         $configure_vars{'OBJEXT'} = $filename . ':' . $.;
  4115.     }
  4116.  
  4117.     # Check for NLS support.
  4118.     if (/AM_GNU_GETTEXT/)
  4119.     {
  4120.         $seen_gettext = 1;
  4121.         $ac_gettext_line = $.;
  4122.         $omit_dependencies{'libintl.h'} = 1;
  4123.     }
  4124.  
  4125.         # Look for ALL_LINGUAS.
  4126.         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
  4127.     {
  4128.         $seen_linguas = 1;
  4129.         $all_linguas = $1;
  4130.         $all_linguas_line = $.;
  4131.     }
  4132.  
  4133.     # Handle configuration headers.  A config header of `[$1]'
  4134.     # means we are actually scanning AM_CONFIG_HEADER from
  4135.     # aclocal.m4.
  4136.     if (/A([CM])_CONFIG_HEADER\s*\((.*)\)/
  4137.         && $2 ne '[$1]')
  4138.     {
  4139.         &am_conf_line_error
  4140.          ($filename, $., "\`automake requires \`AM_CONFIG_HEADER', not \`AC_CONFIG_HEADER'")
  4141.              if $1 eq 'C';
  4142.  
  4143.         $config_header_line = $.;
  4144.         local ($one_hdr);
  4145.         foreach $one_hdr (split (' ', $2))
  4146.         {
  4147.         push (@config_fullnames, $one_hdr);
  4148.         if ($one_hdr =~ /^([^:]+):(.+)$/)
  4149.         {
  4150.             push (@config_names, $1);
  4151.             push (@config_headers, $2);
  4152.         }
  4153.         else
  4154.         {
  4155.             push (@config_names, $one_hdr);
  4156.             push (@config_headers, $one_hdr . '.in');
  4157.         }
  4158.         }
  4159.     }
  4160.  
  4161.         # Handle AC_CANONICAL_*.  Always allow upgrading to
  4162.         # AC_CANONICAL_SYSTEM, but never downgrading.
  4163.     $seen_canonical = $AC_CANONICAL_HOST
  4164.         if ! $seen_canonical
  4165.         && (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
  4166.         $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;
  4167.  
  4168.     $seen_path_xtra = 1 if /AC_PATH_XTRA/;
  4169.  
  4170.         # This macro handles several different things.
  4171.         if (/$AM_INIT_AUTOMAKE_PATTERN/o)
  4172.     {
  4173.         $seen_make_set = 1;
  4174.         $seen_package = 1;
  4175.         $seen_version = 1;
  4176.         $seen_arg_prog = 1;
  4177.         $seen_prog_install = 1;
  4178.         ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
  4179.         $package_version_line = $.;
  4180.     }
  4181.  
  4182.     # This is like AM_INIT_AUTOMAKE, but doesn't actually set the
  4183.     # package and version number.  (This might change in the
  4184.     # future).  Yes, I'm not above hacking Automake so it works
  4185.     # well with other GNU tools -- that is actually the point.
  4186.     if (/AM_INIT_GUILE_MODULE/)
  4187.     {
  4188.         $seen_make_set = 1;
  4189.         $seen_package = 1;
  4190.         $seen_version = 1;
  4191.         $seen_arg_prog = 1;
  4192.         $seen_prog_install = 1;
  4193.         @config_aux_path = ('..');
  4194.     }
  4195.  
  4196.     # Some things required by Automake.
  4197.     $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
  4198.     $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
  4199.  
  4200.     if (/AM_PROG_LEX/)
  4201.     {
  4202.         $configure_vars{'LEX'} = $filename . ':' . $.;
  4203.         $seen_decl_yytext = 1;
  4204.     }
  4205.     if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.in$/)
  4206.     {
  4207.         &am_conf_line_warning ($filename, $., "\`AC_DECL_YYTEXT' is covered by \`AM_PROG_LEX'");
  4208.     }
  4209.     if (/AC_PROG_LEX/ && $filename =~ /configure\.in$/)
  4210.     {
  4211.          &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'");
  4212.     }
  4213.  
  4214.     if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
  4215.     {
  4216.         $configure_vars{$1} = $filename . ':' . $.;
  4217.     }
  4218.     if (/$AC_CHECK_PATTERN/o)
  4219.     {
  4220.         $configure_vars{$3} = $filename . ':' . $.;
  4221.     }
  4222.     if (/$AM_MISSING_PATTERN/o
  4223.         && $1 ne 'ACLOCAL'
  4224.         && $1 ne 'AUTOCONF'
  4225.         && $1 ne 'AUTOMAKE'
  4226.         && $1 ne 'AUTOHEADER')
  4227.     {
  4228.         $configure_vars{$1} = $filename . ':' . $.;
  4229.     }
  4230.  
  4231.     # Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
  4232.     # but later define it elsewhere.  This is pretty hacky.  We
  4233.     # also explicitly avoid INSTALL_SCRIPT and some other
  4234.     # variables because they are defined in header-vars.am.
  4235.     # FIXME.
  4236.     if (/$AC_SUBST_PATTERN/o
  4237.         && $1 ne 'ANSI2KNR'
  4238.         && $1 ne 'INSTALL_SCRIPT'
  4239.         && $1 ne 'INSTALL_DATA')
  4240.     {
  4241.         $configure_vars{$1} = $filename . ':' . $.;
  4242.     }
  4243.  
  4244.         $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
  4245.     if (/AM_MAINTAINER_MODE/)
  4246.     {
  4247.         $seen_maint_mode = 1;
  4248.         $configure_cond{'MAINTAINER_MODE'} = 1;
  4249.     }
  4250.         $seen_package = 1 if /PACKAGE=/;
  4251.  
  4252.     # Skip VERSION of [$2]; that is from AM_INIT_AUTOMAKE.
  4253.         if (/\bVERSION=(\S+)/ && $1 ne '[$2]')
  4254.     {
  4255.         $seen_version = 1;
  4256.         $package_version = $1;
  4257.         $package_version_line = $.;
  4258.     }
  4259.         elsif (/VERSION=/)
  4260.     {
  4261.         $seen_version = 1;
  4262.     }
  4263.  
  4264.     $seen_prog_install = 1 if /AC_PROG_INSTALL/;
  4265.         $seen_lispdir = 1 if /AM_PATH_LISPDIR/;
  4266.  
  4267.         if (/AM_PROG_LIBTOOL/)
  4268.     {
  4269.         $seen_libtool = 1;
  4270.         $libtool_line = $.;
  4271.         $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
  4272.         $configure_vars{'RANLIB'} = $filename . ':' . $.;
  4273.         $configure_vars{'CC'} = $filename . ':' . $.;
  4274.         # AM_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
  4275.         # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
  4276.         $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
  4277.     }
  4278.  
  4279.     $seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);
  4280.  
  4281.     if (/$AM_CONDITIONAL_PATTERN/o)
  4282.     {
  4283.         $configure_cond{$1} = 1;
  4284.     }
  4285.  
  4286.     # Check for Fortran 77 intrinsic and run-time libraries.
  4287.     if (/AC_F77_LIBRARY_LDFLAGS/)
  4288.     {
  4289.         $configure_vars{'FLIBS'} = $filename . ':' . $.;
  4290.     }
  4291.     }
  4292.  
  4293.     close (CONFIGURE);
  4294. }
  4295.  
  4296. # Scan configure.in and aclocal.m4 for interesting things.  We must
  4297. # scan aclocal.m4 because there might be AC_SUBSTs and such there.
  4298. sub scan_configure
  4299. {
  4300.     # Reinitialize libsources here.  This isn't really necessary,
  4301.     # since we currently assume there is only one configure.in.  But
  4302.     # that won't always be the case.
  4303.     %libsources = ();
  4304.  
  4305.     local ($in_ac_output, $in_ac_replace) = (0, 0);
  4306.     local (%make_list, @make_input_list);
  4307.     local ($libobj_iter);
  4308.  
  4309.     &scan_one_configure_file ('configure.in');
  4310.     &scan_one_configure_file ('aclocal.m4')
  4311.     if -f 'aclocal.m4';
  4312.  
  4313.     # Set input and output files if not specified by user.
  4314.     if (! @input_files)
  4315.     {
  4316.     @input_files = @make_input_list;
  4317.     %output_files = %make_list;
  4318.     }
  4319.  
  4320.     &am_conf_error ("\`PACKAGE' not defined in configure.in")
  4321.         if ! $seen_package;
  4322.     &am_conf_error ("\`VERSION' not defined in configure.in")
  4323.         if ! $seen_version;
  4324.  
  4325.     # Look for some files we need.  Always check for these.  This
  4326.     # check must be done for every run, even those where we are only
  4327.     # looking at a subdir Makefile.  We must set relative_dir so that
  4328.     # the file-finding machinery works.
  4329.     local ($relative_dir) = '.';
  4330.     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
  4331.     &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
  4332.         if -f $config_aux_path[0] . '/install.sh';
  4333. }
  4334.  
  4335. ################################################################
  4336.  
  4337. # Set up for Cygnus mode.
  4338. sub check_cygnus
  4339. {
  4340.     return unless $cygnus_mode;
  4341.  
  4342.     &set_strictness ('foreign');
  4343.     $options{'no-installinfo'} = 1;
  4344.     $options{'no-dependencies'} = 1;
  4345.     $use_dependencies = 0;
  4346.  
  4347.     if (! $seen_maint_mode)
  4348.     {
  4349.     &am_conf_error ("\`AM_MAINTAINER_MODE' required when --cygnus specified");
  4350.     }
  4351.  
  4352.     if (! $seen_exeext)
  4353.     {
  4354.     &am_conf_error ("\`AC_EXEEXT' required when --cygnus specified");
  4355.     }
  4356. }
  4357.  
  4358. # Do any extra checking for GNU standards.
  4359. sub check_gnu_standards
  4360. {
  4361.     if ($relative_dir eq '.')
  4362.     {
  4363.     # In top level (or only) directory.
  4364.     &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
  4365.                'AUTHORS', 'ChangeLog');
  4366.     }
  4367.  
  4368.     if ($strictness >= $GNU)
  4369.     {
  4370.     if (defined $options{'no-installman'})
  4371.     {
  4372.         &am_line_error ('AUTOMAKE_OPTIONS',
  4373.                 "option \`no-installman' disallowed by GNU standards");
  4374.     }
  4375.  
  4376.     if (defined $options{'no-installinfo'})
  4377.     {
  4378.         &am_line_error ('AUTOMAKE_OPTIONS',
  4379.                 "option \`no-installinfo' disallowed by GNU standards");
  4380.     }
  4381.     }
  4382. }
  4383.  
  4384. # Do any extra checking for GNITS standards.
  4385. sub check_gnits_standards
  4386. {
  4387.     if ($strictness >= $GNITS)
  4388.     {
  4389.     if (-f $relative_dir . '/COPYING.LIB')
  4390.     {
  4391.         &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
  4392.     }
  4393.     }
  4394.  
  4395.     if ($relative_dir eq '.')
  4396.     {
  4397.     # In top level (or only) directory.
  4398.     &require_file ($GNITS, 'THANKS');
  4399.     }
  4400. }
  4401.  
  4402. ################################################################
  4403. #
  4404. # Functions to handle files of each language.
  4405.  
  4406. # Each `lang_X_rewrite' function follows a simple formula:
  4407. # * Args are the base name and extension of the file.
  4408. # * Return value is 1 if file is to be dealt with, 0 otherwise.
  4409. # Much of the actual processing is handled in handle_single_transform_list.
  4410. # These functions exist so that auxiliary information can be recorded
  4411. # for a later cleanup pass.  Note that the calls to these functions
  4412. # are computed, so don't bother searching for their precise names
  4413. # in the source.
  4414.  
  4415. # Rewrite a single C source file.
  4416. sub lang_c_rewrite
  4417. {
  4418.     local ($base, $ext) = @_;
  4419.  
  4420.     if (defined $options{'ansi2knr'} && $base =~ /_$/)
  4421.     {
  4422.     # FIXME: include line number in error.
  4423.     &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
  4424.     }
  4425.  
  4426.     $de_ansi_files{$base} = 1;
  4427.     return 1;
  4428. }
  4429.  
  4430. # Rewrite a single C++ source file.
  4431. sub lang_cxx_rewrite
  4432. {
  4433.     return 1;
  4434. }
  4435.  
  4436. # Rewrite a single header file.
  4437. sub lang_header_rewrite
  4438. {
  4439.     # Header files are simply ignored.
  4440.     return 0;
  4441. }
  4442.  
  4443. # Rewrite a single yacc file.
  4444. sub lang_yacc_rewrite
  4445. {
  4446.     local ($base, $ext) = @_;
  4447.  
  4448.     &lang_c_rewrite ($base, $ext);
  4449.     $yacc_sources{$base . '.' . $ext} = 1;
  4450.     $ext =~ tr/y/c/;
  4451.     &saw_extension ('c');
  4452.     &push_dist_common ($base . '.' . $ext);
  4453.     return 1;
  4454. }
  4455.  
  4456. # Rewrite a single yacc++ file.
  4457. sub lang_yaccxx_rewrite
  4458. {
  4459.     local ($base, $ext) = @_;
  4460.  
  4461.     $yacc_sources{$base . '.' . $ext} = 1;
  4462.     $ext =~ tr/y/c/;
  4463.     &saw_extension ($ext);
  4464.     &push_dist_common ($base . '.' . $ext);
  4465.     return 1;
  4466. }
  4467.  
  4468. # Rewrite a single lex file.
  4469. sub lang_lex_rewrite
  4470. {
  4471.     local ($base, $ext) = @_;
  4472.  
  4473.     &lang_c_rewrite ($base, $ext);
  4474.     $lex_sources{$base . '.' . $ext} = 1;
  4475.     $ext =~ tr/l/c/;
  4476.     &saw_extension ('c');
  4477.     &push_dist_common ($base . '.' . $ext);
  4478.     return 1;
  4479. }
  4480.  
  4481. # Rewrite a single lex++ file.
  4482. sub lang_lexxx_rewrite
  4483. {
  4484.     local ($base, $ext) = @_;
  4485.  
  4486.     $lex_sources{$base . '.' . $ext} = 1;
  4487.     $ext =~ tr/l/c/;
  4488.     &saw_extension ($ext);
  4489.     &push_dist_common ($base . '.' . $ext);
  4490.     return 1;
  4491. }
  4492.  
  4493. # Rewrite a single assembly file.
  4494. sub lang_asm_rewrite
  4495. {
  4496.     return 1;
  4497. }
  4498.  
  4499. # Rewrite a single Fortran 77 file.
  4500. sub lang_f77_rewrite
  4501. {
  4502.     return 1;
  4503. }
  4504.  
  4505. # Rewrite a single Objective C file.
  4506. sub lang_objc_rewrite
  4507. {
  4508.     return 1;
  4509. }
  4510.  
  4511. # The lang_X_finish functions are called after all source file
  4512. # processing is done.  Each should handle defining rules for the
  4513. # language, etc.  A finish function is only called if a source file of
  4514. # the appropriate type has been seen.
  4515.  
  4516. sub lang_c_finish
  4517. {
  4518.     # Push all libobjs files onto de_ansi_files.  We actually only
  4519.     # push files which exist in the current directory, and which are
  4520.     # genuine source files.
  4521.     local ($file);
  4522.     foreach $file (keys %libsources)
  4523.     {
  4524.     if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
  4525.     {
  4526.         $de_ansi_files{$1} = 1;
  4527.     }
  4528.     }
  4529.  
  4530.     if (defined $options{'ansi2knr'} && keys %de_ansi_files)
  4531.     {
  4532.      # Make all _.c files depend on their corresponding .c files.
  4533.      local ($base, @objects);
  4534.      foreach $base (sort keys %de_ansi_files)
  4535.      {
  4536.         # Each _.c file must depend on ansi2knr; otherwise it
  4537.         # might be used in a parallel build before it is built.
  4538.         # We need to support files in the srcdir and in the build
  4539.         # dir (because these files might be auto-generated.  But
  4540.         # we can't use $< -- some makes only define $< during a
  4541.         # suffix rule.
  4542.          $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
  4543.                   . '$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
  4544.                   . '`if test -f $(srcdir)/' . $base . '.c'
  4545.                   . '; then echo $(srcdir)/' . $base . '.c'
  4546.                   . '; else echo ' . $base . '.c; fi` '
  4547.                   . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
  4548.                   . '| $(ANSI2KNR) > ' . $base . "_.c\n");
  4549.          push (@objects, $base . '_'
  4550.           . ($seen_objext ? '.$(OBJEXT)' : '.o'));
  4551.          push (@objects, $base . '_.lo') if $seen_libtool;
  4552.      }
  4553.  
  4554.      # Make all _.o (and _.lo) files depend on ansi2knr.
  4555.      # Use a sneaky little hack to make it print nicely.
  4556.      &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
  4557.     }
  4558.  
  4559.     if (! defined $configure_vars{'CC'})
  4560.     {
  4561.     # FIXME: line number.
  4562.     &am_error ("C source seen but \`CC' not defined in \`configure.in'");
  4563.     }
  4564. }
  4565.  
  4566. # A helper which computes a sorted list of all C++ extensions which
  4567. # were seen.
  4568. sub cxx_extensions
  4569. {
  4570.     local ($key, @r);
  4571.     foreach $key (sort keys %extension_seen)
  4572.     {
  4573.     push (@r, '.' . $key) if $extension_map{$key} eq 'cxx';
  4574.     }
  4575.     return @r;
  4576. }
  4577.  
  4578. sub lang_cxx_finish
  4579. {
  4580.     local (@cxx_list) = &cxx_extensions;
  4581.     local ($cxx_count) = scalar @cxx_list;
  4582.     if ($cxx_count)
  4583.     {
  4584.     push (@suffixes, @cxx_list);
  4585.  
  4586.     local ($ltcompile, $ltlink) = &libtool_compiler;
  4587.  
  4588.     &define_configure_variable ("CXXFLAGS");
  4589.     &define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)');
  4590.     &define_variable ('LTCXXCOMPILE',
  4591.               $ltcompile . '$(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)')
  4592.         if ($seen_libtool);
  4593.  
  4594.     &define_variable ('CXXLD', '$(CXX)');
  4595.     &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@');
  4596.  
  4597.     local ($ext);
  4598.     foreach $ext (@cxx_list)
  4599.     {
  4600.         $output_rules .= ("$ext.o:\n"
  4601.                   . "\t\$(CXXCOMPILE) -c \$<\n");
  4602.         # FIXME: Using cygpath should be somehow conditional.
  4603.         $output_rules .= ("$ext.obj:\n"
  4604.                   . "\t\$(CXXCOMPILE) -c `cygpath -w \$<`\n")
  4605.         if ($seen_objext);
  4606.         $output_rules .= ("$ext.lo:\n"
  4607.                   . "\t\$(LTCXXCOMPILE) -c \$<\n")
  4608.         if ($seen_libtool);
  4609.     }
  4610.  
  4611.     if (! defined $configure_vars{'CXX'})
  4612.     {
  4613.         &am_error ("C++ source seen but \`CXX' not defined in \`configure.in'");
  4614.     }
  4615.     }
  4616. }
  4617.  
  4618. sub lang_header_finish
  4619. {
  4620.     # Nothing to do.
  4621. }
  4622.  
  4623. # This is a helper for both lex and yacc.
  4624. sub yacc_lex_finish_helper
  4625. {
  4626.     return if defined $language_scratch{'lex-yacc-done'};
  4627.     $language_scratch{'lex-yacc-done'} = 1;
  4628.  
  4629.     # If there is more than one distinct yacc (resp lex) source file
  4630.     # in a given directory, then the `ylwrap' program is required to
  4631.     # allow parallel builds to work correctly.  FIXME: for now, no
  4632.     # line number.
  4633.     &require_config_file ($FOREIGN, 'ylwrap');
  4634.     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
  4635.     {
  4636.     &define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
  4637.     }
  4638.     else
  4639.     {
  4640.     &define_variable ('YLWRAP', '$(srcdir)/ylwrap');
  4641.     }
  4642. }
  4643.  
  4644. sub lang_yacc_finish
  4645. {
  4646.     return if defined $language_scratch{'yacc-done'};
  4647.     $language_scratch{'yacc-done'} = 1;
  4648.  
  4649.     local ($file, $base, $hname, $cname);
  4650.     local (%seen_suffix) = ();
  4651.     local (@yacc_files) = sort keys %yacc_sources;
  4652.     local ($yacc_count) = scalar (@yacc_files);
  4653.     foreach $file (@yacc_files)
  4654.     {
  4655.     $file =~ /(\..*)$/;
  4656.     &output_yacc_build_rule ($1, $yacc_count > 1)
  4657.         if ! defined $seen_suffix{$1};
  4658.     $seen_suffix{$1} = 1;
  4659.  
  4660.     # Now generate rule to make the header file.  This should only
  4661.     # be generated if `yacc -d' specified.  But right now there is
  4662.     # no way to determine that.  FIXME: examine AM_YFLAGS?
  4663.     $file =~ /^(.*)\.(y|yy|y\+\+|yxx)$/;
  4664.     $base = $1;
  4665.     ($hname = $2) =~ tr/y/h/;
  4666.     ($cname = $2) =~ tr/y/c/;
  4667.     $output_rules .= "${base}.${hname}: ${base}.${cname}\n";
  4668.  
  4669.     # If the files are built in the build directory, then we want
  4670.     # to remove them with `make clean'.  If they are in srcdir
  4671.     # they shouldn't be touched.  However, we can't determine this
  4672.     # statically, and the GNU rules say that yacc/lex output files
  4673.     # should be removed by maintainer-clean.  So that's what we
  4674.     # do.
  4675.     push (@maintainer_clean_files, $base . $hname, $base . $cname);
  4676.     }
  4677.     $output_rules .= "\n";
  4678.  
  4679.     if (! defined $configure_vars{'YACC'})
  4680.     {
  4681.     &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
  4682.     }
  4683.     if (&variable_defined ('YACCFLAGS'))
  4684.     {
  4685.     &am_line_error ('YACCFLAGS',
  4686.             "\`YACCFLAGS' obsolete; use \`YFLAGS' instead");
  4687.     }
  4688.  
  4689.     if ($yacc_count > 1)
  4690.     {
  4691.     &yacc_lex_finish_helper;
  4692.     }
  4693. }
  4694.  
  4695. sub lang_yaccxx_finish
  4696. {
  4697.     &lang_yacc_finish;
  4698. }
  4699.  
  4700. sub lang_lex_finish
  4701. {
  4702.     return if defined $language_scratch{'lex-done'};
  4703.     $language_scratch{'lex-done'} = 1;
  4704.  
  4705.     local (%seen_suffix) = ();
  4706.     local ($file, $cname);
  4707.     local ($lex_count) = scalar (keys %lex_sources);
  4708.     foreach $file (sort keys %lex_sources)
  4709.     {
  4710.     $file =~ /(\..*)$/;
  4711.     &output_lex_build_rule ($1, $lex_count > 1)
  4712.         if (! defined $seen_suffix{$1});
  4713.     $seen_suffix{$1} = 1;
  4714.  
  4715.     # If the files are built in the build directory, then we want
  4716.     # to remove them with `make clean'.  If they are in srcdir
  4717.     # they shouldn't be touched.  However, we can't determine this
  4718.     # statically, and the GNU rules say that yacc/lex output files
  4719.     # should be removed by maintainer-clean.  So that's what we
  4720.     # do.
  4721.     $file =~ /^(.*)\.(l|ll|l\+\+|lxx)$/;
  4722.     ($cname = $2) =~ tr/y/c/;
  4723.     push (@maintainer_clean_files, $1 . $cname);
  4724.     }
  4725.  
  4726.     if (! defined $configure_vars{'LEX'})
  4727.     {
  4728.     &am_error ("lex source seen but \`LEX' not defined in \`configure.in'");
  4729.     }
  4730.     if (! $seen_decl_yytext)
  4731.     {
  4732.     &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'");
  4733.     }
  4734.  
  4735.     if ($lex_count > 1)
  4736.     {
  4737.     &yacc_lex_finish_helper;
  4738.     }
  4739. }
  4740.  
  4741. sub lang_lexxx_finish
  4742. {
  4743.     &lang_lex_finish;
  4744. }
  4745.  
  4746. sub lang_asm_finish
  4747. {
  4748.     # Pretend we're C.
  4749.     &lang_c_finish;
  4750. }
  4751.  
  4752. # A helper which computes a sorted list of all Fortran 77 extensions
  4753. # which were seen.
  4754. sub f77_extensions
  4755. {
  4756.     local ($key, @r);
  4757.     foreach $key (sort keys %extension_seen)
  4758.     {
  4759.     push (@r, '.' . $key) if $extension_map{$key} eq 'f77';
  4760.     }
  4761.     return @r;
  4762. }
  4763.  
  4764. sub lang_f77_finish
  4765. {
  4766.     local (@f77_list) = &f77_extensions;
  4767.     local ($f77_count) = scalar @f77_list;
  4768.     if ($f77_count)
  4769.     {
  4770.     push (@suffixes, @f77_list);
  4771.  
  4772.     local ($ltcompile, $ltlink) = &libtool_compiler;
  4773.  
  4774.     &define_configure_variable ('FFLAGS');
  4775.     &define_variable ('F77COMPILE', '$(F77) $(AM_FFLAGS) $(FFLAGS)');
  4776.     &define_variable ('LTF77COMPILE',
  4777.               $ltcompile . '$(F77) $(AM_FFLAGS) $(FFLAGS)')
  4778.         if ($seen_libtool);
  4779.  
  4780.     &define_variable ('F77LD', '$(F77)');
  4781.     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(LDFLAGS) -o $@');
  4782.  
  4783.     local ($ext);
  4784.     foreach $ext (@f77_list)
  4785.     {
  4786.         $output_rules .= ("$ext.o:\n"
  4787.                   . "\t\$(F77COMPILE) -c \$<\n");
  4788.         # FIXME: Using cygpath should be somehow conditional.
  4789.         $output_rules .= ("$ext.obj:\n"
  4790.                   . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
  4791.         if ($seen_objext);
  4792.         $output_rules .= ("$ext.lo:\n"
  4793.                   . "\t\$(LTF77COMPILE) -c \$<\n")
  4794.         if ($seen_libtool);
  4795.     }
  4796.  
  4797.     if (! defined $configure_vars{'F77'})
  4798.     {
  4799.         &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
  4800.     }
  4801.     }
  4802. }
  4803.  
  4804. # Preprocessed Fortran 77
  4805. #
  4806. # The current support for preprocessing Fortran 77 just involves passing
  4807. # `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
  4808. # to the Fortran 77 compiler, since this is how GNU Make does it; see
  4809. # the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
  4810. # (specifically, from info file `(make)Catalogue of Rules').
  4811. #
  4812. # A better approach would be to write an Autoconf test
  4813. # (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
  4814. # Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
  4815. # AC_PROG_FPP should test the Fortran 77 compiler first for
  4816. # preprocessing capabilities, and then fall back on cpp (if cpp were
  4817. # available).
  4818. sub lang_ppf77_finish
  4819. {
  4820.     local ($ext) = 'F';
  4821.     last unless $extension_seen{$ext};
  4822.     push (@suffixes, '.' . $ext);
  4823.  
  4824.     local ($ltcompile, $ltlink) = &libtool_compiler;
  4825.  
  4826.     &define_configure_variable ('FFLAGS');
  4827.     &define_variable ('F77COMPILE', '$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)');
  4828.     &define_variable ('LTF77COMPILE',
  4829.               $ltcompile . '$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)')
  4830.     if ($seen_libtool);
  4831.  
  4832.     &define_variable ('F77LD', '$(F77)');
  4833.     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(LDFLAGS) -o $@');
  4834.  
  4835.     $output_rules .= ("$ext.o:\n"
  4836.               . "\t\$(F77COMPILE) -c \$<\n");
  4837.     # FIXME: Using cygpath should be somehow conditional.
  4838.     $output_rules .= ("$ext.obj:\n"
  4839.               . "\t\$(F77COMPILE) -c `cygpath -w \$<`\n")
  4840.     if ($seen_objext);
  4841.     $output_rules .= ("$ext.lo:\n"
  4842.               . "\t\$(LTF77COMPILE) -c \$<\n")
  4843.     if ($seen_libtool);
  4844.  
  4845.     # We also handle the case of preprocessing `.F' files into `.f'
  4846.     # files.
  4847.     $output_rules .= ("$ext.f:\n"
  4848.               . "\t\$(F77COMPILE) -F \$<\n");
  4849.  
  4850.     if (! defined $configure_vars{'F77'})
  4851.     {
  4852.     &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'");
  4853.     }
  4854. }
  4855.  
  4856. sub lang_ratfor_finish
  4857. {
  4858.     local ($ext) = 'r';
  4859.     last unless $extension_seen{$ext};
  4860.     push (@suffixes, '.' . $ext);
  4861.  
  4862.     local ($ltcompile, $ltlink) = &libtool_compiler;
  4863.  
  4864.     &define_configure_variable ('FFLAGS');
  4865.     &define_configure_variable ('RFLAGS');
  4866.     &define_variable ('RCOMPILE', '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)');
  4867.     &define_variable ('LTRCOMPILE',
  4868.               $ltcompile . '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)')
  4869.     if ($seen_libtool);
  4870.  
  4871.     &define_variable ('F77LD', '$(F77)');
  4872.     &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS) $(LDFLAGS) -o $@');
  4873.  
  4874.     $output_rules .= ("$ext.o:\n"
  4875.               . "\t\$(RCOMPILE) -c \$<\n");
  4876.     # FIXME: Using cygpath should be somehow conditional.
  4877.     $output_rules .= ("$ext.obj:\n"
  4878.               . "\t\$(RCOMPILE) -c `cygpath -w \$<`\n")
  4879.     if ($seen_objext);
  4880.     $output_rules .= ("$ext.lo:\n"
  4881.               . "\t\$(LTRCOMPILE) -c \$<\n")
  4882.     if ($seen_libtool);
  4883.  
  4884.     # We also handle the case of preprocessing `.r' files into `.f'
  4885.     # files.
  4886.     $output_rules .= ("$ext.f:\n"
  4887.               . "\t\$(RCOMPILE) -F \$<\n");
  4888.  
  4889.     if (! defined $configure_vars{'F77'})
  4890.     {
  4891.     &am_error ("Ratfor source seen but \`F77' not defined in \`configure.in'");
  4892.     }
  4893. }
  4894.  
  4895. sub lang_objc_finish
  4896. {
  4897.     push (@suffixes, '.m');
  4898.  
  4899.     local ($ltcompile, $ltlink) = &libtool_compiler;
  4900.  
  4901.     &define_configure_variable ("OBJCFLAGS");
  4902.     &define_variable ('OBJCCOMPILE', '$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)');
  4903.     &define_variable ('LTOBJCCOMPILE',
  4904.                       $ltcompile . '$(OBJC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)')
  4905.         if ($seen_libtool);
  4906.     
  4907.     &define_variable ('OBJCLD', '$(OBJC)');
  4908.     &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(LDFLAGS) -o $@');
  4909.     
  4910.     $output_rules .= (".m.o:\n"
  4911.                       . "\t\$(OBJCCOMPILE) -c \$<\n");
  4912.     # FIXME: Using cygpath should be somehow conditional.
  4913.     $output_rules .= (".m.obj:\n"
  4914.                       . "\t\$(OBJCCOMPILE) -c `cygpath -w \$<`\n")
  4915.         if ($seen_objext);
  4916.     $output_rules .= (".m.lo:\n"
  4917.                       . "\t\$(LTOBJCCOMPILE) -c \$<\n")
  4918.         if ($seen_libtool);
  4919.     
  4920.     if (! defined $configure_vars{'OBJC'})
  4921.     {
  4922.     &am_error ("Objective C source seen but \`OBJC' not defined in \`configure.in'");
  4923.     }
  4924. }
  4925.  
  4926. # A helper which computes a sorted list of all ObjC extensions which
  4927. # were seen.
  4928. sub objc_extensions
  4929. {
  4930.     local ($key, @r);
  4931.     foreach $key (sort keys %extension_seen)
  4932.     {
  4933.     push (@r, '.' . $key) if $extension_map{$key} eq 'objc';
  4934.     }
  4935.     return @r;
  4936. }
  4937.  
  4938. # A helper which decides whether libtool is needed.  Returns prefix
  4939. # for compiler and linker.
  4940. sub libtool_compiler
  4941. {
  4942.     local ($ltcompile, $ltlink) = ('', '');
  4943.     if ($seen_libtool)
  4944.     {
  4945.     &define_configure_variable ("LIBTOOL");
  4946.     $ltcompile = '$(LIBTOOL) --mode=compile ';
  4947.     $ltlink = '$(LIBTOOL) --mode=link ';
  4948.     }
  4949.     return ($ltcompile, $ltlink);
  4950. }
  4951.  
  4952. # Given a hash table of linker names, pick the name that has the most
  4953. # precedence.  This is lame, but something has to have global
  4954. # knowledge in order to eliminate the conflict.  Add more linkers as
  4955. # required.
  4956. sub resolve_linker
  4957. {
  4958.     local (%linkers) = @_;
  4959.  
  4960.     return 'CXXLINK'
  4961.     if defined $linkers{'CXXLINK'};
  4962.     return 'F77LINK'
  4963.     if defined $linkers{'F77LINK'};
  4964.     return 'OBJCLINK'
  4965.         if defined $linkers{'OBJCLINK'};
  4966.     return 'LINK';
  4967. }
  4968.  
  4969. # Called to indicate that an extension was used.
  4970. sub saw_extension
  4971. {
  4972.     local ($ext) = @_;
  4973.     $extension_seen{$ext} = 1;
  4974. }
  4975.  
  4976. # Called to ask whether source files have been seen . If HEADERS is 1,
  4977. # headers can be included.
  4978. sub saw_sources_p
  4979. {
  4980.     local ($headers) = @_;
  4981.  
  4982.     if ($headers)
  4983.     {
  4984.     $headers = 0;
  4985.     }
  4986.     else
  4987.     {
  4988.     $headers = defined $extension_seen{'header'};
  4989.     }
  4990.  
  4991.     return scalar keys %extension_seen > $headers;
  4992. }
  4993.  
  4994. # Register a single language.  If LINKER is the empty string, it means
  4995. # to use the C linker.  DEANSI_P should only be 1 for languages where
  4996. # de-ansi-fication makes sense (i.e., C).  EXTENSIONS is a list of
  4997. # file extensions to match (no `.' included).
  4998. sub register_language
  4999. {
  5000.     local ($language, $linker, $deansi_p, @extensions) = @_;
  5001.  
  5002.     local ($iter);
  5003.     foreach $iter (@extensions)
  5004.     {
  5005.     if (defined $extension_map{$iter})
  5006.     {
  5007.         print STDERR
  5008.         "automake: programming error: duplicate extension $iter\n";
  5009.         exit 1;
  5010.     }
  5011.     $extension_map{$iter} = $language;
  5012.     }
  5013.  
  5014.     $language_map{$language . '-ansi-p'} = $deansi_p;
  5015.     $language_map{$language . '-linker'} = $linker;
  5016. }
  5017.  
  5018.  
  5019. ################################################################
  5020.  
  5021. # Pretty-print something.  HEAD is what should be printed at the
  5022. # beginning of the first line, FILL is what should be printed at the
  5023. # beginning of every subsequent line.
  5024. sub pretty_print_internal
  5025. {
  5026.     local ($head, $fill, @values) = @_;
  5027.  
  5028.     local ($column) = length ($head);
  5029.     local ($result) = $head;
  5030.  
  5031.     # Fill length is number of characters.  However, each Tab
  5032.     # character counts for eight.  So we count the number of Tabs and
  5033.     # multiply by 7.
  5034.     local ($fill_length) = length ($fill);
  5035.     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
  5036.  
  5037.     local ($bol) = ($head eq '');
  5038.     foreach (@values)
  5039.     {
  5040.     # "71" because we also print a space.
  5041.     if ($column + length ($_) > 71)
  5042.     {
  5043.         $result .= " \\\n" . $fill;
  5044.         $column = $fill_length;
  5045.         $bol = 1;
  5046.     }
  5047.  
  5048.     $result .= ' ' unless ($bol);
  5049.     $result .= $_;
  5050.     $column += length ($_) + 1;
  5051.     $bol = 0;
  5052.     }
  5053.  
  5054.     $result .= "\n";
  5055.     return $result;
  5056. }
  5057.  
  5058. # Pretty-print something and append to output_vars.
  5059. sub pretty_print
  5060. {
  5061.     $output_vars .= &pretty_print_internal (@_);
  5062. }
  5063.  
  5064. # Pretty-print something and append to output_rules.
  5065. sub pretty_print_rule
  5066. {
  5067.     $output_rules .= &pretty_print_internal (@_);
  5068. }
  5069.  
  5070.  
  5071. ################################################################
  5072.  
  5073. # See if a target exists.
  5074. sub target_defined
  5075. {
  5076.     local ($target) = @_;
  5077.     return defined $targets{$target};
  5078. }
  5079.  
  5080. # See if two conditionals are the same.
  5081. sub conditional_same
  5082. {
  5083.     local ($cond1, $cond2) = @_;
  5084.  
  5085.     return (&conditional_true_when ($cond1, $cond2)
  5086.         && &conditional_true_when ($cond2, $cond1));
  5087. }
  5088.  
  5089. # See if a conditional is true.  Both arguments are conditional
  5090. # strings.  This returns true if the first conditional is true when
  5091. # the second conditional is true.
  5092. sub conditional_true_when
  5093. {
  5094.     local ($cond, $when) = @_;
  5095.  
  5096.     # Check the easy case first.
  5097.     if ($cond eq $when)
  5098.     {
  5099.     return 1;
  5100.     }
  5101.  
  5102.     # Check each component of $cond, which looks @COND1@@COND2@.
  5103.     foreach $comp (split ('@', $cond))
  5104.     {
  5105.     # The way we split will give null strings between each
  5106.     # condition.
  5107.     next if ! $comp;
  5108.  
  5109.     if (index ($when, '@' . $comp . '@') == -1)
  5110.     {
  5111.         return 0;
  5112.     }
  5113.     }
  5114.  
  5115.     return 1;
  5116. }
  5117.  
  5118. # Check for an ambiguous conditional.  This is called when a variable
  5119. # or target is being defined conditionally.  If we already know about
  5120. # a definition that is true under the same conditions, then we have an
  5121. # ambiguity.
  5122. sub check_ambiguous_conditional
  5123. {
  5124.     local ($var_name, $cond) = @_;
  5125.     local (@cond_vals) = split (' ', $conditional{$var_name});
  5126.     while (@cond_vals)
  5127.     {
  5128.     local ($vcond) = shift (@cond_vals);
  5129.     shift (@cond_vals);
  5130.     if (&conditional_true_when ($vcond, $cond)
  5131.         || &conditional_true_when ($cond, $vcond))
  5132.     {
  5133.         &am_line_error ($var_name,
  5134.                 "$var_name multiply defined in condition");
  5135.     }
  5136.     }
  5137. }
  5138.  
  5139. # See if a variable exists.  The first argument is the variable name,
  5140. # and the optional second argument is the condition which we should
  5141. # check.  If no condition is given, we currently return true if the
  5142. # variable is defined under any condition.
  5143. sub variable_defined
  5144. {
  5145.     local ($var, $cond) = @_;
  5146.     if (defined $targets{$var})
  5147.     {
  5148.     &am_line_error ($var, "\`$var' is target; expected variable");
  5149.     return 0;
  5150.     }
  5151.     elsif (defined $contents{$var})
  5152.     {
  5153.     if ($cond && $conditional{$var})
  5154.     {
  5155.         # We have been asked to check for a particular condition,
  5156.         # and the variable is defined conditionally.  We need to
  5157.         # look through the conditions under which the variable is
  5158.         # defined, and see if any of them match the conditional we
  5159.         # have been asked to check.
  5160.         local (@cond_vars) = split (' ', $conditional{$var});
  5161.         while (@cond_vars)
  5162.         {
  5163.         if (&conditional_same ($cond, shift (@cond_vars)))
  5164.         {
  5165.             # Even a conditional examination is good enough
  5166.             # for us.  FIXME: really should maintain examined
  5167.             # status on a per-condition basis.
  5168.             $content_seen{$var} = 1;
  5169.             return 1;
  5170.         }
  5171.         shift (@cond_vars);
  5172.         }
  5173.  
  5174.         # The variable is not defined for the given condition.
  5175.         return 0;
  5176.     }
  5177.  
  5178.     $content_seen{$var} = 1;
  5179.     return 1;
  5180.     }
  5181.     return 0;
  5182. }
  5183.  
  5184. # Mark a variable as examined.
  5185. sub examine_variable
  5186. {
  5187.     local ($var) = @_;
  5188.     &variable_defined ($var);
  5189. }
  5190.  
  5191. # Quote a value in order to put it in $conditional.  We need to quote
  5192. # spaces, and we need to handle null strings, so that we can later
  5193. # retrieve values by splitting on space.
  5194. sub quote_cond_val
  5195. {
  5196.     local ($val) = @_;
  5197.     $val =~ s/ /\001/g;
  5198.     $val =~ s/\t/\003/g;
  5199.     $val = "\002" if $val eq '';
  5200.     return $val;
  5201. }
  5202.  
  5203. # Unquote a value in $conditional.
  5204. sub unquote_cond_val
  5205. {
  5206.     local ($val) = @_;
  5207.     $val =~ s/\001/ /g;
  5208.     $val =~ s/\003/\t/g;
  5209.     $val =~ s/\002//g;
  5210.     return $val;
  5211. }
  5212.  
  5213. # Return the set of conditions for which a variable is defined.
  5214.  
  5215. # If the variable is not defined conditionally, and is not defined in
  5216. # terms of any variables which are defined conditionally, then this
  5217. # returns the empty list.
  5218.  
  5219. # If the variable is defined conditionally, but is not defined in
  5220. # terms of any variables which are defined conditionally, then this
  5221. # returns the list of conditions for which the variable is defined.
  5222.  
  5223. # If the variable is defined in terms of any variables which are
  5224. # defined conditionally, then this returns a full set of permutations
  5225. # of the subvariable conditions.  For example, if the variable is
  5226. # defined in terms of a variable which is defined for @COND_TRUE@,
  5227. # then this returns both @COND_TRUE@ and @COND_FALSE@.  This is
  5228. # because we will need to define the variable under both conditions.
  5229.  
  5230. sub variable_conditions
  5231. {
  5232.     local ($var) = @_;
  5233.     local (%uniqify);
  5234.     local ($cond);
  5235.  
  5236.     %vars_scanned = ();
  5237.     foreach $cond (&variable_conditions_sub ($var, '', ()))
  5238.     {
  5239.     $uniqify{$cond} = 1;
  5240.     }
  5241.  
  5242.     return keys %uniqify;
  5243. }
  5244.  
  5245. # A subroutine of variable_conditions.  We only return conditions
  5246. # which are true for all the conditions in @PARENT_CONDS.
  5247. sub variable_conditions_sub
  5248. {
  5249.     local ($var, $parent, @parent_conds) = @_;
  5250.     local (@new_conds) = ();
  5251.  
  5252.     if (defined $vars_scanned{$var})
  5253.     {
  5254.     &am_line_error ($parent, "variable \`$var' recursively defined");
  5255.     return ();
  5256.     }
  5257.     $vars_scanned{$var} = 1;
  5258.  
  5259.     if (! $conditional{$var})
  5260.     {
  5261.     foreach (split (' ', $contents{$var}))
  5262.     {
  5263.         # If a comment seen, just leave.
  5264.         last if /^#/;
  5265.  
  5266.         # Handle variable substitutions.
  5267.         if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
  5268.         {
  5269.         push (@new_conds,
  5270.               &variable_conditions_sub ($1, $var, @parent_conds));
  5271.         }
  5272.     }
  5273.  
  5274.     # Now we want to return all permutations of the subvariable
  5275.     # conditions.
  5276.     local (%allconds, $item);
  5277.     foreach $item (@new_conds)
  5278.     {
  5279.         foreach (split ('@', $item))
  5280.         {
  5281.         next if ! $_;
  5282.         s/_(TRUE|FALSE)$//;
  5283.         $allconds{$_ . '_TRUE'} = 1;
  5284.         }
  5285.     }
  5286.  
  5287.     # Unset our entry in vars_scanned.  We only care about recursive
  5288.     # definitions.
  5289.     delete $vars_scanned{$var};
  5290.  
  5291.     return &variable_conditions_permutations (keys %allconds);
  5292.     }
  5293.  
  5294.     local (@this_conds) = ();
  5295.     local (@condvals) = split (' ', $conditional{$var});
  5296.     while (@condvals)
  5297.     {
  5298.     local ($cond) = shift (@condvals);
  5299.     local ($val) = &unquote_cond_val (shift (@condvals));
  5300.  
  5301.     if (@parent_conds)
  5302.     {
  5303.         local ($ok) = 1;
  5304.         local ($parent_cond);
  5305.         foreach $parent_cond (@parent_conds)
  5306.         {
  5307.         if (! &conditional_true_when ($parent_cond, $cond))
  5308.         {
  5309.             $ok = 0;
  5310.             last;
  5311.         }
  5312.         }
  5313.  
  5314.         next if ! $ok;
  5315.     }
  5316.  
  5317.     push (@this_conds, $cond);
  5318.  
  5319.     push (@parent_conds, $cond);
  5320.     local (@subvar_conds) = ();
  5321.     foreach (split (' ', $val))
  5322.     {
  5323.         # If a comment seen, just leave.
  5324.         last if /^#/;
  5325.  
  5326.         # Handle variable substitutions.
  5327.         if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
  5328.         {
  5329.         push (@subvar_conds,
  5330.               &variable_conditions_sub ($1, $var, @parent_conds));
  5331.         }
  5332.     }
  5333.     pop (@parent_conds);
  5334.  
  5335.     # If there are no conditional subvariables, then we want to
  5336.     # return this condition.  Otherwise, we want to return the
  5337.     # permutations of the subvariables.
  5338.     if (! @subvar_conds)
  5339.     {
  5340.         push (@new_conds, $cond);
  5341.     }
  5342.     else
  5343.     {
  5344.         push (@new_conds, &variable_conditions_reduce (@subvar_conds));
  5345.     }
  5346.     }
  5347.  
  5348.     # Unset our entry in vars_scanned.  We only care about recursive
  5349.     # definitions.
  5350.     delete $vars_scanned{$var};
  5351.  
  5352.     return @new_conds
  5353.     if ! $parent;
  5354.  
  5355.     # If we are being called on behalf of another variable, we need to
  5356.     # return all possible permutations of the conditions.  We have
  5357.     # already handled everything in @this_conds along with their
  5358.     # subvariables.  We now need to add any permutations that are not
  5359.     # in @this_conds.
  5360.     local ($this_cond);
  5361.     foreach $this_cond (@this_conds)
  5362.     {
  5363.     local (@perms) =
  5364.         &variable_conditions_permutations (split('@', $this_cond));
  5365.     local ($perm);
  5366.     foreach $perm (@perms)
  5367.     {
  5368.         local ($scan);
  5369.         local ($ok) = 1;
  5370.         foreach $scan (@this_conds)
  5371.         {
  5372.         if (&conditional_true_when ($perm, $scan)
  5373.             || &conditional_true_when ($scan, $perm))
  5374.         {
  5375.             $ok = 0;
  5376.             last;
  5377.         }
  5378.         }
  5379.         next if ! $ok;
  5380.  
  5381.         if (@parent_conds)
  5382.         {
  5383.         local ($ok) = 1;
  5384.         local ($parent_cond);
  5385.         foreach $parent_cond (@parent_conds)
  5386.         {
  5387.             if (! &conditional_true_when ($parent_cond, $perm))
  5388.             {
  5389.             $ok = 0;
  5390.             last;
  5391.             }
  5392.         }
  5393.  
  5394.         next if ! $ok;
  5395.         }
  5396.  
  5397.         # This permutation was not already handled, and is valid
  5398.         # for the parents.
  5399.         push (@new_conds, $perm);
  5400.     }
  5401.     }
  5402.  
  5403.     return @new_conds;
  5404. }
  5405.  
  5406. # Subroutine for variable_conditions_sort
  5407. sub variable_conditions_cmp
  5408. {
  5409.     local ($as) = $a;
  5410.     $as =~ s/[^@]//g;
  5411.     local ($bs) = $b;
  5412.     $bs =~ s/[^@]//g;
  5413.     return (length ($as) <=> length ($bs)
  5414.         || $a cmp $b);
  5415. }
  5416.  
  5417. # Sort a list of conditionals so that only the exclusive ones are
  5418. # retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
  5419. # @COND1_TRUE@ are in the list, discard the latter.
  5420. sub variable_conditions_reduce
  5421. {
  5422.     local (@conds) = @_;
  5423.     local (@ret) = ();
  5424.     local ($cond);
  5425.     foreach $cond (sort variable_conditions_cmp @conds)
  5426.     {
  5427.     local ($ok) = 1;
  5428.     local ($scan);
  5429.     foreach $scan (@ret)
  5430.     {
  5431.         if (&conditional_true_when ($cond, $scan))
  5432.         {
  5433.         $ok = 0;
  5434.         last;
  5435.         }
  5436.     }
  5437.     next if ! $ok;
  5438.     push (@ret, $cond);
  5439.     }
  5440.  
  5441.     return @ret;
  5442. }
  5443.  
  5444. # Return a list of permutations of a conditional string.
  5445. sub variable_conditions_permutations
  5446. {
  5447.     local (@comps) = @_;
  5448.     return ()
  5449.     if ! @comps;
  5450.     local ($comp) = shift (@comps);
  5451.     return &variable_conditions_permutations (@comps)
  5452.     if $comp eq '';
  5453.     local ($neg) = $comp;
  5454.     $neg =~ s/TRUE$/TRUEO/;
  5455.     $neg =~ s/FALSE$/TRUE/;
  5456.     $neg =~ s/TRUEO$/FALSE/;
  5457.     local (@ret);
  5458.     local ($sub);
  5459.     foreach $sub (&variable_conditions_permutations (@comps))
  5460.     {
  5461.     push (@ret, '@' . $comp . '@' . $sub);
  5462.     push (@ret, '@' . $neg . '@' . $sub);
  5463.     }
  5464.     if (! @ret)
  5465.     {
  5466.     push (@ret, '@' . $comp . '@');
  5467.     push (@ret, '@' . $neg . '@');
  5468.     }
  5469.     return @ret;
  5470. }
  5471.  
  5472. # Warn if a variable is conditionally defined.  This is called if we
  5473. # are using the value of a variable.
  5474. sub variable_conditionally_defined
  5475. {
  5476.     local ($var, $parent) = @_;
  5477.     if ($conditional{$var})
  5478.     {
  5479.     if ($parent)
  5480.     {
  5481.         &am_line_error ($parent,
  5482.                 "warning: automake does not support conditional definition of $var in $parent");
  5483.     }
  5484.     else
  5485.     {
  5486.         &am_line_error ($parent,
  5487.                 "warning: automake does not support $var being defined conditionally")
  5488.     }
  5489.     }
  5490. }
  5491.  
  5492. # Get the value of a variable.  This just returns $contents, but warns
  5493. # if the variable is conditionally defined.
  5494. sub variable_value
  5495. {
  5496.     local ($var) = @_;
  5497.     &variable_conditionally_defined ($var);
  5498.     return $contents{$var};
  5499. }
  5500.  
  5501. # Convert a variable value to a list, split as whitespace.  This will
  5502. # recursively follow $(...) and ${...} inclusions.  It preserves @...@
  5503. # substitutions.  If COND is 'all', then all values under all
  5504. # conditions should be returned; if COND is a particular condition
  5505. # (all conditions are surrounded by @...@) then only the value for
  5506. # that condition should be returned; otherwise, warn if VAR is
  5507. # conditionally defined.  SCANNED is a global hash listing whose keys
  5508. # are all the variables already scanned; it is an error to rescan a
  5509. # variable.
  5510. sub value_to_list
  5511. {
  5512.     local ($var, $val, $cond) = @_;
  5513.     local (@result);
  5514.  
  5515.     foreach (split (' ', $val))
  5516.     {
  5517.     # If a comment seen, just leave.
  5518.     last if /^#/;
  5519.  
  5520.     # Handle variable substitutions.
  5521.     if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
  5522.     {
  5523.         local ($varname) = $1;
  5524.  
  5525.         # If the user uses a losing variable name, just ignore it.
  5526.         # This isn't ideal, but people have requested it.
  5527.         next if ($varname =~ /\@.*\@/);
  5528.  
  5529.         local ($from, $to);
  5530.         local (@temp_list);
  5531.         if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
  5532.         {
  5533.         $varname = $1;
  5534.         $to = $3;
  5535.         ($from = $2) =~ s/(\W)/\\$1/g;
  5536.         }
  5537.  
  5538.         # Find the value.
  5539.         @temp_list = &variable_value_as_list_worker ($1, $cond, $var);
  5540.  
  5541.         # Now rewrite the value if appropriate.
  5542.         if ($from)
  5543.         {
  5544.         grep (s/$from$/$to/, @temp_list);
  5545.         }
  5546.  
  5547.         push (@result, @temp_list);
  5548.     }
  5549.     else
  5550.     {
  5551.         push (@result, $_);
  5552.     }
  5553.     }
  5554.  
  5555.     return @result;
  5556. }
  5557.  
  5558. # Return contents of variable as list, split as whitespace.  This will
  5559. # recursively follow $(...) and ${...} inclusions.  It preserves @...@
  5560. # substitutions.  If COND is 'all', then all values under all
  5561. # conditions should be returned; if COND is a particular condition
  5562. # (all conditions are surrounded by @...@) then only the value for
  5563. # that condition should be returned; otherwise, warn if VAR is
  5564. # conditionally defined.  If PARENT is specified, it is the name of
  5565. # the including variable; this is only used for error reports.
  5566. sub variable_value_as_list_worker
  5567. {
  5568.     local ($var, $cond, $parent) = @_;
  5569.     local (@result);
  5570.  
  5571.     if (defined $targets{$var})
  5572.     {
  5573.     &am_line_error ($var, "\`$var' is target; expected variable");
  5574.     }
  5575.     elsif (! defined $contents{$var})
  5576.     {
  5577.     &am_line_error ($parent, "variable \`$var' not defined");
  5578.     }
  5579.     elsif (defined $vars_scanned{$var})
  5580.     {
  5581.     # `vars_scanned' is a global we use to keep track of which
  5582.     # variables we've already examined.
  5583.     &am_line_error ($parent, "variable \`$var' recursively defined");
  5584.     }
  5585.     elsif ($cond eq 'all' && $conditional{$var})
  5586.     {
  5587.     $vars_scanned{$var} = 1;
  5588.     local (@condvals) = split (' ', $conditional{$var});
  5589.     while (@condvals)
  5590.     {
  5591.         shift (@condvals);
  5592.         local ($val) = &unquote_cond_val (shift (@condvals));
  5593.         push (@result, &value_to_list ($var, $val, $cond));
  5594.     }
  5595.     }
  5596.     elsif ($cond && $conditional{$var})
  5597.     {
  5598.     $vars_scanned{$var} = 1;
  5599.     local (@condvals) = split (' ', $conditional{$var});
  5600.     local ($onceflag);
  5601.     while (@condvals)
  5602.     {
  5603.         local ($vcond) = shift (@condvals);
  5604.         local ($val) = &unquote_cond_val (shift (@condvals));
  5605.         if (&conditional_true_when ($vcond, $cond))
  5606.         {
  5607.         # Warn if we have an ambiguity.  It's hard to know how
  5608.         # to handle this case correctly.
  5609.         &variable_conditionally_defined ($var, $parent)
  5610.             if $onceflag;
  5611.         $onceflag = 1;
  5612.         push (@result, &value_to_list ($var, $val, $cond));
  5613.         }
  5614.     }
  5615.     }
  5616.     else
  5617.     {
  5618.     $vars_scanned{$var} = 1;
  5619.     &variable_conditionally_defined ($var, $parent);
  5620.     $content_seen{$var} = 1;
  5621.     push (@result, &value_to_list ($var, $contents{$var}, $cond));
  5622.     }
  5623.  
  5624.     # Unset our entry in vars_scanned.  We only care about recursive
  5625.     # definitions.
  5626.     delete $vars_scanned{$var};
  5627.  
  5628.     return @result;
  5629. }
  5630.  
  5631. # This is just a wrapper for variable_value_as_list_worker that
  5632. # initializes the global hash `vars_scanned'.  This hash is used to
  5633. # avoid infinite recursion.
  5634. sub variable_value_as_list
  5635. {
  5636.     local ($var, $cond, $parent) = @_;
  5637.     %vars_scanned = ();
  5638.     return &variable_value_as_list_worker ($var, $cond, $parent);
  5639. }
  5640.  
  5641. # Define a new variable, but only if not already defined.
  5642. sub define_variable
  5643. {
  5644.     local ($var, $value) = @_;
  5645.  
  5646.     if (! defined $contents{$var})
  5647.     {
  5648.     $output_vars .= $var . ' = ' . $value . "\n";
  5649.     $contents{$var} = $value;
  5650.     $content_seen{$var} = 1;
  5651.     }
  5652. }
  5653.  
  5654. # Like define_variable, but the value is a list, and the variable may
  5655. # be defined conditionally.  The second argument is the conditional
  5656. # under which the value should be defined; this should be the empty
  5657. # string to define the variable unconditionally.  The third argument
  5658. # is a list holding the values to use for the variable.  The value is
  5659. # pretty printed in the output file.
  5660. sub define_pretty_variable
  5661. {
  5662.     local ($var, $cond, @value) = @_;
  5663.     if (! defined $contents{$var}
  5664.     || ($cond && ! &variable_defined ($var, $cond)))
  5665.     {
  5666.     $contents{$var} = join (' ', @value);
  5667.     if ($cond)
  5668.     {
  5669.         if ($conditional{$var})
  5670.         {
  5671.         $conditional{$var} .= ' ';
  5672.         }
  5673.         else
  5674.         {
  5675.         $conditional{$var} = '';
  5676.         }
  5677.         $conditional{$var} .= ($cond
  5678.                    . ' '
  5679.                    . "e_cond_val ($contents{$var}));
  5680.     }
  5681.     &pretty_print ($cond . $var . ' = ', $cond, @value);
  5682.     $content_seen{$var} = 1;
  5683.     }
  5684. }
  5685.  
  5686. # Like define_variable, but define a variable to be the configure
  5687. # substitution by the same name.
  5688. sub define_configure_variable
  5689. {
  5690.     local ($var) = @_;
  5691.     local ($value) = '@' . $var . '@';
  5692.     &define_variable ($var, $value);
  5693. }
  5694.  
  5695. # Define a variable that represents a program to run.  If in Cygnus
  5696. # mode, the program is searched for in the build (or source) tree.
  5697. # Otherwise no searching is done at all.  Arguments are:
  5698. # * VAR      Name of variable to define
  5699. # * WHATDIR  Either `src' or `build', depending on where program should
  5700. #            be found.  (runtest is in srcdir!)
  5701. # * SUBDIR   Subdir of top-level dir
  5702. # * PROGRAM  Name of program
  5703. # * OVERRIDE If specified, the name of the program to use when not in
  5704. #            Cygnus mode.  Defaults to PROGRAM.
  5705. sub define_program_variable
  5706. {
  5707.     local ($var, $whatdir, $subdir, $program, $override) = @_;
  5708.  
  5709.     if (! $override)
  5710.     {
  5711.     $override = $program;
  5712.     }
  5713.  
  5714.     if ($cygnus_mode)
  5715.     {
  5716.     local ($full) = ('$(top_' . $whatdir . 'dir)/../'
  5717.              . $subdir . '/' . $program);
  5718.     &define_variable ($var, ('`if test -f ' . $full
  5719.                  . '; then echo ' . $full . '; else echo '
  5720.                  . $program . '; fi`'));
  5721.     }
  5722.     else
  5723.     {
  5724.     &define_variable ($var, $override);
  5725.     }
  5726. }
  5727.  
  5728.  
  5729. ################################################################
  5730.  
  5731. # Read Makefile.am and set up %contents.  Simultaneously copy lines
  5732. # from Makefile.am into $output_trailer or $output_vars as
  5733. # appropriate.  NOTE we put rules in the trailer section.  We want
  5734. # user rules to come after our generated stuff.
  5735. sub read_am_file
  5736. {
  5737.     local ($amfile) = @_;
  5738.     local (*AM_FILE);
  5739.  
  5740.     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
  5741.     print "automake: reading $amfile\n" if $verbose;
  5742.  
  5743.     local ($saw_bk) = 0;
  5744.     local ($was_rule) = 0;
  5745.     local ($spacing) = '';
  5746.     local ($comment) = '';
  5747.     local ($last_var_name) = '';
  5748.     local ($blank) = 0;
  5749.  
  5750.     while (<AM_FILE>)
  5751.     {
  5752.     if (/$IGNORE_PATTERN/o)
  5753.     {
  5754.         # Merely delete comments beginning with two hashes.
  5755.     }
  5756.     elsif (/$WHITE_PATTERN/o)
  5757.     {
  5758.         # Stick a single white line before the incoming macro or rule.
  5759.         $spacing = "\n";
  5760.         $blank = 1;
  5761.     }
  5762.     elsif (/$COMMENT_PATTERN/o)
  5763.     {
  5764.         # Stick comments before the incoming macro or rule.  Make
  5765.         # sure a blank line preceeds first block of comments.
  5766.         $spacing = "\n" unless $blank;
  5767.         $blank = 1;
  5768.         $comment .= $spacing . $_;
  5769.         $spacing = '';
  5770.     }
  5771.     else
  5772.     {
  5773.         last;
  5774.     }
  5775.     }
  5776.  
  5777.     $output_vars .= $comment . "\n";
  5778.     $comment = '';
  5779.     $spacing = "\n";
  5780.  
  5781.     local ($is_ok_macro);
  5782.     while ($_)
  5783.     {
  5784.     $_ .= "\n"
  5785.         unless substr ($_, -1, 1) eq "\n";
  5786.  
  5787.     # Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
  5788.     # used by users.  @MAINT@ is an anachronism now.
  5789.     $_ =~ s/\@MAINT\@//g
  5790.         unless $seen_maint_mode;
  5791.  
  5792.     if (/$IGNORE_PATTERN/o)
  5793.     {
  5794.         # Merely delete comments beginning with two hashes.
  5795.     }
  5796.     elsif (/$WHITE_PATTERN/o)
  5797.     {
  5798.         # Stick a single white line before the incoming macro or rule.
  5799.         $spacing = "\n";
  5800.         &am_line_error ($., "blank line following trailing backslash")
  5801.         if $saw_bk;
  5802.     }
  5803.     elsif (/$COMMENT_PATTERN/o)
  5804.     {
  5805.         # Stick comments before the incoming macro or rule.
  5806.         $comment .= $spacing . $_;
  5807.         $spacing = '';
  5808.         &am_line_error ($., "comment following trailing backslash")
  5809.         if $saw_bk;
  5810.     }
  5811.     elsif ($saw_bk)
  5812.     {
  5813.         if ($was_rule)
  5814.         {
  5815.         $output_trailer .= join ('', @conditional_stack) . $_;
  5816.         $saw_bk = /\\$/;
  5817.         }
  5818.         else
  5819.         {
  5820.         $saw_bk = /\\$/;
  5821.         # Chop newline and backslash if this line is
  5822.         # continued.  ensure trailing whitespace exists.
  5823.         chop if $saw_bk;
  5824.         chop if $saw_bk;
  5825.         $contents{$last_var_name} .= ' '
  5826.             unless $contents{$last_var_name} =~ /\s$/;
  5827.         $contents{$last_var_name} .= $_;
  5828.         if (@conditional_stack)
  5829.         {
  5830.             $conditional{$last_var_name} .= "e_cond_val ($_);
  5831.         }
  5832.         }
  5833.     }
  5834.     elsif (/$IF_PATTERN/o)
  5835.     {
  5836.         &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
  5837.         if (! $configure_cond{$1});
  5838.         push (@conditional_stack, "\@" . $1 . "_TRUE\@");
  5839.     }
  5840.     elsif (/$ELSE_PATTERN/o)
  5841.     {
  5842.         if (! @conditional_stack)
  5843.         {
  5844.         &am_line_error ($., "else without if");
  5845.         }
  5846.         elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
  5847.         {
  5848.         &am_line_error ($., "else after else");
  5849.         }
  5850.         else
  5851.         {
  5852.         $conditional_stack[$#conditional_stack]
  5853.             =~ s/_TRUE\@$/_FALSE\@/;
  5854.         }
  5855.     }
  5856.     elsif (/$ENDIF_PATTERN/o)
  5857.     {
  5858.         if (! @conditional_stack)
  5859.         {
  5860.         &am_line_error ($., "endif without if");
  5861.         }
  5862.         else
  5863.         {
  5864.         pop @conditional_stack;
  5865.         }
  5866.     }
  5867.     elsif (/$RULE_PATTERN/o)
  5868.     {
  5869.         # Found a rule.
  5870.         $was_rule = 1;
  5871.         if (defined $contents{$1}
  5872.         && (@conditional_stack
  5873.             ? ! defined $conditional{$1}
  5874.             : defined $conditional{$1}))
  5875.         {
  5876.         &am_line_error ($1,
  5877.                 "$1 defined both conditionally and unconditionally");
  5878.         }
  5879.         # Value here doesn't matter; for targets we only note
  5880.         # existence.
  5881.         $contents{$1} = 1;
  5882.         $targets{$1} = 1;
  5883.         local ($cond_string) = join ('', @conditional_stack);
  5884.         if (@conditional_stack)
  5885.         {
  5886.         if ($conditional{$1})
  5887.         {
  5888.             &check_ambiguous_conditional ($1, $cond_string);
  5889.             $conditional{$1} .= ' ';
  5890.         }
  5891.         else
  5892.         {
  5893.             $conditional{$1} = '';
  5894.         }
  5895.         $conditional{$1} .= $cond_string . ' 1';
  5896.         }
  5897.         $content_lines{$1} = $.;
  5898.         $output_trailer .= $comment . $spacing . $cond_string . $_;
  5899.         $comment = $spacing = '';
  5900.         $saw_bk = /\\$/;
  5901.  
  5902.         # Check the rule for being a suffix rule. If so, store in
  5903.         # a hash.
  5904.  
  5905.         local ($source_suffix);
  5906.         local ($object_suffix);
  5907.  
  5908.         if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN)) 
  5909.         {
  5910.           $suffix_rules{$source_suffix} = $object_suffix;
  5911.           print "Sources ending in .$source_suffix become .$object_suffix\n" if $verbose;
  5912.           $source_suffix_pattern = "(" . join('|', keys %suffix_rules) . ")";
  5913.         }
  5914.  
  5915.         # FIXME: make sure both suffixes are in SUFFIXES? Or set
  5916.         # SUFFIXES from suffix_rules?
  5917.     }
  5918.     elsif (($is_ok_macro = /$MACRO_PATTERN/o)
  5919.            || /$BOGUS_MACRO_PATTERN/o)
  5920.     {
  5921.         # Found a macro definition.
  5922.         $was_rule = 0;
  5923.         $last_var_name = $1;
  5924.         if (defined $contents{$1}
  5925.         && (@conditional_stack
  5926.             ? ! defined $conditional{$1}
  5927.             : defined $conditional{$1}))
  5928.         {
  5929.         &am_line_error ($1,
  5930.                 "$1 defined both conditionally and unconditionally");
  5931.         }
  5932.         local ($value);
  5933.         if ($3 ne '' && substr ($3, -1) eq "\\")
  5934.         {
  5935.         $value = substr ($3, 0, length ($3) - 1);
  5936.         }
  5937.         else
  5938.         {
  5939.         $value = $3;
  5940.         }
  5941.         local ($type) = $2;
  5942.         if ($type eq '+')
  5943.         {
  5944.         if (! defined $contents{$last_var_name}
  5945.             && defined $configure_vars{$last_var_name})
  5946.         {
  5947.             $contents{$last_var_name} = '@' . $last_var_name . '@';
  5948.         }
  5949.         $contents{$last_var_name} .= ' ' . $value;
  5950.         }
  5951.         else
  5952.         {
  5953.         $contents{$last_var_name} = $value;
  5954.         # The first assignment to a macro sets the line
  5955.         # number.  Ideally I suppose we would associate line
  5956.         # numbers with random bits of text.
  5957.         $content_lines{$last_var_name} = $.;
  5958.         }
  5959.         local ($cond_string) = join ('', @conditional_stack);
  5960.         if (@conditional_stack)
  5961.         {
  5962.         local ($found) = 0;
  5963.         local ($val);
  5964.         if ($conditional{$last_var_name})
  5965.         {
  5966.             if ($type eq '+')
  5967.             {
  5968.             # If we're adding to the conditional, and it
  5969.             # exists, then we might want to simply replace
  5970.             # the old value with the new one.
  5971.             local (@new_vals, @cond_vals);
  5972.             @cond_vals = split (' ', $conditional{$last_var_name});
  5973.             while (@cond_vals)
  5974.             {
  5975.                 local ($vcond) = shift (@cond_vals);
  5976.                 push (@new_vals, $vcond);
  5977.                 if (&conditional_same ($vcond, $cond_string))
  5978.                 {
  5979.                 $found = 1;
  5980.                 $val = (&unquote_cond_val (shift (@cond_vals))
  5981.                     . ' ' . $value);
  5982.                 push (@new_vals, "e_cond_val ($val));
  5983.                 }
  5984.                 else
  5985.                 {
  5986.                 push (@new_vals, shift (@cond_vals));
  5987.                 }
  5988.             }
  5989.             if ($found)
  5990.             {
  5991.                 $conditional{$last_var_name}
  5992.                     = join (' ', @new_vals);
  5993.             }
  5994.             }
  5995.  
  5996.             if (! $found)
  5997.             {
  5998.             &check_ambiguous_conditional ($last_var_name,
  5999.                               $cond_string);
  6000.             $conditional{$last_var_name} .= ' ';
  6001.             $val = $value;
  6002.             }
  6003.         }
  6004.         else
  6005.         {
  6006.             $conditional{$last_var_name} = '';
  6007.             $val = $contents{$last_var_name};
  6008.         }
  6009.         if (! $found)
  6010.         {
  6011.             $conditional{$last_var_name} .= ($cond_string
  6012.                              . ' '
  6013.                              . "e_cond_val ($val));
  6014.         }
  6015.         }
  6016.  
  6017.         # FIXME: this doesn't always work correctly; it will group
  6018.         # all comments for a given variable, no matter where
  6019.         # defined.
  6020.         $am_vars{$last_var_name} = $comment . $spacing;
  6021.         $def_type{$last_var_name} = ($type eq ':') ? ':' : '';
  6022.         push (@var_list, $last_var_name);
  6023.         $comment = $spacing = '';
  6024.         $saw_bk = /\\$/;
  6025.  
  6026.         # Error if bogus.
  6027.         &am_line_error ($., "bad macro name \`$last_var_name'")
  6028.         if ! $is_ok_macro;
  6029.     }
  6030.         elsif (/$INCLUDE_PATTERN/o)
  6031.         {
  6032.             local ($path) = $1;
  6033.  
  6034.             if ($path =~ s/^\$\(top_srcdir\)\///)
  6035.             {
  6036.                 push (@include_stack, "\$\(top_srcdir\)/$path");
  6037.             }
  6038.             else
  6039.             {
  6040.                 $path =~ s/\$\(srcdir\)\///;
  6041.                 push (@include_stack, "\$\(srcdir\)/$path");
  6042.                 $path = $relative_dir . "/" . $path;
  6043.             }
  6044.             &read_am_file ($path);
  6045.         }
  6046.     else
  6047.         {
  6048.         # This isn't an error; it is probably a continued rule.
  6049.         # In fact, this is what we assume.
  6050.         $was_rule = 1;
  6051.         $output_trailer .= ($comment . $spacing
  6052.                 . join ('', @conditional_stack) . $_);
  6053.         $comment = $spacing = '';
  6054.         $saw_bk = /\\$/;
  6055.     }
  6056.  
  6057.     $_ = <AM_FILE>;
  6058.     }
  6059.  
  6060.     $output_trailer .= $comment;
  6061.  
  6062.     &am_error ("unterminated conditionals: " . join (' ', @conditional_stack))
  6063.     if (@conditional_stack);
  6064. }
  6065.  
  6066. # Read main am file.
  6067. sub read_main_am_file
  6068. {
  6069.     local ($amfile) = @_;
  6070.  
  6071.     $output_vars = ("# $in_file_name generated automatically by automake "
  6072.             . $VERSION . " from $am_file_name\n");
  6073.  
  6074.     # Generate copyright for generated Makefile.in.
  6075.     $output_vars .= $gen_copyright;
  6076.  
  6077.     # The keys here are variables we want to dump at the end of this
  6078.     # function.  The values are corresponding comments.
  6079.     local (%am_vars) = ();
  6080.     local (@var_list) = ();
  6081.     local (%def_type) = ();
  6082.  
  6083.     &read_am_file ($amfile);
  6084.  
  6085.     # Compute relative location of the top object directory.
  6086.     local (@topdir) = ();
  6087.     foreach (split (/\//, $relative_dir))
  6088.     {
  6089.     next if $_ eq '.' || $_ eq '';
  6090.     if ($_ eq '..')
  6091.     {
  6092.         pop @topdir;
  6093.     }
  6094.     else
  6095.     {
  6096.         push (@topdir, '..');
  6097.     }
  6098.     }
  6099.     @topdir = ('.') if ! @topdir;
  6100.  
  6101.     $top_builddir = join ('/', @topdir);
  6102.     local ($build_rx);
  6103.     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
  6104.     $output_vars .= &file_contents_with_transform
  6105.                         ('s/\@top_builddir\@/' . $build_rx . '/g;',
  6106.              'header-vars');
  6107.  
  6108.     # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
  6109.     # this should use generic %configure_vars method.
  6110.     if ($seen_canonical)
  6111.     {
  6112.     local ($curs, %vars);
  6113.     $vars{'host_alias'} = 'host_alias';
  6114.     $vars{'host_triplet'} = 'host';
  6115.     if ($seen_canonical == $AC_CANONICAL_SYSTEM)
  6116.     {
  6117.         $vars{'build_alias'} = 'build_alias';
  6118.         $vars{'build_triplet'} = 'build';
  6119.         $vars{'target_alias'} = 'target_alias';
  6120.         $vars{'target_triplet'} = 'target';
  6121.     }
  6122.     foreach $curs (sort keys %vars)
  6123.     {
  6124.         $output_vars .= "$curs = \@$vars{$curs}\@\n";
  6125.         $contents{$curs} = "\@$vars{$curs}\@";
  6126.     }
  6127.     }
  6128.  
  6129.     local ($curs);
  6130.     foreach $curs (sort keys %configure_vars)
  6131.     {
  6132.     &define_configure_variable ($curs);
  6133.     }
  6134.  
  6135.     # Now dump the variables that were defined.  We do it in the same
  6136.     # order in which they were defined (skipping duplicates).
  6137.     local (%done);
  6138.     foreach $curs (@var_list)
  6139.     {
  6140.     next if $done{$curs};
  6141.     $done{$curs} = 1;
  6142.  
  6143.     $output_vars .= $am_vars{$curs};
  6144.     if ($conditional{$curs})
  6145.     {
  6146.         local (@cond_vals) = split (' ', $conditional{$curs});
  6147.         while (@cond_vals)
  6148.         {
  6149.         local ($vcond) = shift (@cond_vals);
  6150.         local ($val) = &unquote_cond_val (shift (@cond_vals));
  6151.         $output_vars .= ($vcond . $curs
  6152.                  . ' ' . $def_type{$curs} . '= '
  6153.                  . $val . "\n");
  6154.         }
  6155.     }
  6156.     else
  6157.     {
  6158.         $output_vars .= ($curs . ' ' . $def_type{$curs} . '= '
  6159.                  . $contents{$curs} . "\n");
  6160.     }
  6161.     }
  6162. }
  6163.  
  6164. ################################################################
  6165.  
  6166. sub initialize_global_constants
  6167. {
  6168.     # Values for AC_CANONICAL_*
  6169.     $AC_CANONICAL_HOST = 1;
  6170.     $AC_CANONICAL_SYSTEM = 2;
  6171.  
  6172.     # Associative array of standard directory names.  Entry is TRUE if
  6173.     # corresponding directory should be installed during
  6174.     # 'install-exec' phase.
  6175.     %exec_dir_p =
  6176.     ('bin', 1,
  6177.      'sbin', 1,
  6178.      'libexec', 1,
  6179.      'data', 0,
  6180.      'sysconf', 1,
  6181.      'localstate', 1,
  6182.      'lib', 1,
  6183.      'info', 0,
  6184.      'man', 0,
  6185.      'include', 0,
  6186.      'oldinclude', 0,
  6187.      'pkgdata', 0,
  6188.      'pkglib', 1,
  6189.      'pkginclude', 0
  6190.      );
  6191.  
  6192.     # Commonly found files we look for and automatically include in
  6193.     # DISTFILES.
  6194.     @common_files =
  6195.     (
  6196.      "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
  6197.      "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
  6198.      "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
  6199.      "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
  6200.      'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
  6201.      'ylwrap', 'acinclude.m4', @libtoolize_files,
  6202.      'missing'
  6203.      );
  6204.  
  6205.     # Commonly used files we auto-include, but only sometimes.
  6206.     @common_sometimes =
  6207.     (
  6208.      "aclocal.m4", "acconfig.h", "config.h.top",
  6209.      "config.h.bot", "stamp-h.in", 'stamp-vti'
  6210.      );
  6211.  
  6212.     $USAGE = "\
  6213.   -a, --add-missing     add missing standard files to package
  6214.   --amdir=DIR           directory storing config files
  6215.   --build-dir=DIR       directory where build being done (for dependencies)
  6216.   -c, --copy            with -a, copy missing files (default is symlink)
  6217.   --cygnus              assume program is part of Cygnus-style tree
  6218.   --foreign             set strictness to foreign
  6219.   --gnits               set strictness to gnits
  6220.   --gnu                 set strictness to gnu
  6221.   --help                print this help, then exit
  6222.   -i, --include-deps    include generated dependencies in Makefile.in
  6223.   --no-force            only update Makefile.in's that are out of date
  6224.   -o DIR, --output-dir=DIR
  6225.                         put generated Makefile.in's into DIR
  6226.   --srcdir-name=DIR     name used for srcdir (for dependencies)
  6227.   -v, --verbose         verbosely list files processed
  6228.   --version             print version number, then exit\n";
  6229.  
  6230.     # Copyright on generated Makefile.ins.
  6231.     $gen_copyright = "\
  6232. # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
  6233. # This Makefile.in is free software; the Free Software Foundation
  6234. # gives unlimited permission to copy and/or distribute it,
  6235. # with or without modifications, as long as this notice is preserved.
  6236.  
  6237. # This program is distributed in the hope that it will be useful,
  6238. # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  6239. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  6240. # PARTICULAR PURPOSE.
  6241. ";
  6242.  
  6243.     # Ignore return result from chmod, because it might give an error
  6244.     # if we chmod a symlink.
  6245.     $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
  6246.     $dist{'dist-tarZ'} = ("\t"
  6247.              . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
  6248.              . "\n");
  6249.     $dist{'dist-shar'} = ("\t"
  6250.              . 'shar $(distdir) | gzip > $(distdir).shar.gz'
  6251.              . "\n");
  6252.     $dist{'dist-zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
  6253.     $dist{'dist'} = "\t" .  'GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
  6254.     $dist_trailer = "\t" . '-rm -rf $(distdir)' . "\n";
  6255. }
  6256.  
  6257. # (Re)-Initialize per-Makefile.am variables.
  6258. sub initialize_per_input
  6259. {
  6260.     # These two variables are used when generating each Makefile.in.
  6261.     # They hold the Makefile.in until it is ready to be printed.
  6262.     $output_rules = '';
  6263.     $output_vars = '';
  6264.     $output_trailer = '';
  6265.     $output_all = '';
  6266.     $output_header = '';
  6267.  
  6268.     # Suffixes found during a run.
  6269.     @suffixes = ();
  6270.  
  6271.     # This holds the contents of a Makefile.am, as parsed by
  6272.     # read_am_file.
  6273.     %contents = ();
  6274.  
  6275.     # This holds the names which are targets.  These also appear in
  6276.     # %contents.
  6277.     %targets = ();
  6278.  
  6279.     # For a variable or target which is defined conditionally, this
  6280.     # holds an array of the conditional values.  The array is composed
  6281.     # of pairs of condition strings (the variables which configure
  6282.     # will substitute) and values (the value of a target is
  6283.     # meaningless).  For an unconditional variable, this is empty.
  6284.     %conditional = ();
  6285.  
  6286.     # This holds the line numbers at which various elements of
  6287.     # %contents are defined.
  6288.     %content_lines = ();
  6289.  
  6290.     # This holds a 1 if a particular variable was examined.
  6291.     %content_seen = ();
  6292.  
  6293.     # This is the conditional stack.
  6294.     @conditional_stack = ();
  6295.  
  6296.     # This holds the set of included files.
  6297.     @include_stack = ();
  6298.  
  6299.     # This holds the "relative directory" of the current Makefile.in.
  6300.     # Eg for src/Makefile.in, this is "src".
  6301.     $relative_dir = '';
  6302.  
  6303.     # This holds a list of files that are included in the
  6304.     # distribution.
  6305.     %dist_common = ();
  6306.  
  6307.     # List of dependencies for the obvious targets.
  6308.     @install_data = ();
  6309.     @install_exec = ();
  6310.     @uninstall = ();
  6311.     @installdirs = ();
  6312.  
  6313.     @info = ();
  6314.     @dvi = ();
  6315.     @all = ();
  6316.     @check = ();
  6317.     @check_tests = ();
  6318.     @installcheck = ();
  6319.     @clean = ();
  6320.  
  6321.     @phony = ();
  6322.  
  6323.     # A list of files deleted by `maintainer-clean'.
  6324.     @maintainer_clean_files = ();
  6325.  
  6326.     # These are pretty obvious, too.  They are used to define the
  6327.     # SOURCES and OBJECTS variables.
  6328.     @sources = ();
  6329.     @objects = ();
  6330.  
  6331.     # These variables track inclusion of various compile-related .am
  6332.     # files.  $included_generic_compile is TRUE if the basic code has
  6333.     # been included.  $included_knr_compile is TRUE if the ansi2knr
  6334.     # code has been included.  $included_libtool_compile is TRUE if
  6335.     # libtool support has been included.
  6336.     $included_generic_compile = 0;
  6337.     $included_knr_compile = 0;
  6338.     $included_libtool_compile = 0;
  6339.  
  6340.     # TRUE if install targets should work recursively.
  6341.     $recursive_install = 0;
  6342.  
  6343.     # All .P files.
  6344.     %dep_files = ();
  6345.  
  6346.     # Strictness levels.
  6347.     $strictness = $default_strictness;
  6348.     $strictness_name = $default_strictness_name;
  6349.  
  6350.     # Options from AUTOMAKE_OPTIONS.
  6351.     %options = ();
  6352.  
  6353.     # Whether or not dependencies are handled.  Can be further changed
  6354.     # in handle_options.
  6355.     $use_dependencies = $cmdline_use_dependencies;
  6356.  
  6357.     # Per Makefile.am.
  6358.     $local_maint_charset = $maint_charset;
  6359.  
  6360.     # All yacc and lex source filenames for this directory.  Use
  6361.     # filenames instead of raw count so that multiple instances are
  6362.     # counted correctly (eg one yacc file can appear in multiple
  6363.     # programs without harm).
  6364.     %yacc_sources = ();
  6365.     %lex_sources = ();
  6366.  
  6367.     # This is a list of all targets to run during "make dist".
  6368.     @dist_targets = ();
  6369.  
  6370.     # Keys in this hash are the basenames of files which must depend
  6371.     # on ansi2knr.
  6372.     %de_ansi_files = ();
  6373.  
  6374.     # This maps the source extension of a suffix rule to its
  6375.     # corresponding output extension.
  6376.     %suffix_rules = ();
  6377.  
  6378.     # This is the name of the recursive `all' target to use.
  6379.     $all_target = 'all-recursive';
  6380.  
  6381.     # This keeps track of which extensions we've seen (that we care
  6382.     # about).
  6383.     %extension_seen = ();
  6384.  
  6385.     # This is random scratch space for the language finish functions.
  6386.     # Don't randomly overwrite it; examine other uses of keys first.
  6387.     %language_scratch = ();
  6388. }
  6389.  
  6390.  
  6391. ################################################################
  6392.  
  6393. # Return contents of a file from $am_dir, automatically skipping
  6394. # macros or rules which are already known.  Runs command on each line
  6395. # as it is read; this command can modify $_.
  6396. sub file_contents_with_transform
  6397. {
  6398.     local ($command, $basename) = @_;
  6399.     local ($file) = $am_dir . '/' . $basename . '.am';
  6400.  
  6401.     if ($command ne '' && substr ($command, -1) ne ';')
  6402.     {
  6403.     die "automake: programming error in file_contents_with_transform: $command\n";
  6404.     }
  6405.  
  6406.     open (FC_FILE, $file)
  6407.     || die "automake: installation error: cannot open \`$file'\n";
  6408.     # Looks stupid?
  6409.     # print "automake: reading $file\n" if $verbose;
  6410.  
  6411.     local ($was_rule) = 0;
  6412.     local ($result_vars) = '';
  6413.     local ($result_rules) = '';
  6414.     local ($comment) = '';
  6415.     local ($spacing) = "\n";
  6416.     local ($skipping) = 0;
  6417.     local ($had_chars);
  6418.  
  6419.     while (<FC_FILE>)
  6420.     {
  6421.     $_ =~ s/\@MAINTAINER_MODE_TRUE\@//g
  6422.         unless $seen_maint_mode;
  6423.  
  6424.     $had_chars = length ($_) && $_ ne "\n";
  6425.     eval $command;
  6426.     # If the transform caused all the characters to go away, then
  6427.     # ignore the line.  Why do this?  Because in Perl 4, a "next"
  6428.     # inside of an eval doesn't affect a loop outside the eval.
  6429.     # So we can't pass in a "transform" that uses next.  We used
  6430.     # to do this.  "Empty" also means consisting of a single
  6431.     # newline.
  6432.     next if $had_chars && ($_ eq '' || $_ eq "\n");
  6433.  
  6434.     if (/$IGNORE_PATTERN/o)
  6435.     {
  6436.         # Merely delete comments beginning with two hashes.
  6437.     }
  6438.     elsif (/$WHITE_PATTERN/o)
  6439.     {
  6440.         # Stick a single white line before the incoming macro or rule.
  6441.         $spacing = "\n";
  6442.         &am_line_error ($., "blank line following trailing backslash")
  6443.         if $saw_bk;
  6444.     }
  6445.     elsif (/$COMMENT_PATTERN/o)
  6446.     {
  6447.         # Stick comments before the incoming macro or rule.
  6448.         $comment .= $spacing . $_;
  6449.         $spacing = '';
  6450.         &am_line_error ($., "comment following trailing backslash")
  6451.         if $saw_bk;
  6452.     }
  6453.     elsif ($saw_bk)
  6454.     {
  6455.         if ($was_rule)
  6456.         {
  6457.         $result_rules .= $_ if ! $skipping;
  6458.         }
  6459.         else
  6460.         {
  6461.         $result_vars .= $_ if ! $skipping;
  6462.         }
  6463.         $saw_bk = /\\$/;
  6464.     }
  6465.     elsif (/$RULE_PATTERN/o)
  6466.     {
  6467.         # Found a rule.
  6468.         $was_rule = 1;
  6469.         $skipping = defined $contents{$1};
  6470.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  6471.         $comment = $spacing = '';
  6472.         $saw_bk = /\\$/;
  6473.     }
  6474.     elsif (/$MACRO_PATTERN/o)
  6475.     {
  6476.         # Found a variable reference.
  6477.         $was_rule = 0;
  6478.         $skipping = defined $contents{$1};
  6479.         $result_vars .= $comment . $spacing . $_ if ! $skipping;
  6480.         $comment = $spacing = '';
  6481.         $saw_bk = /\\$/;
  6482.     }
  6483.     else
  6484.     {
  6485.         # This isn't an error; it is probably a continued rule.
  6486.         # In fact, this is what we assume.
  6487.         $was_rule = 1;
  6488.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  6489.         $comment = $spacing = '';
  6490.         $saw_bk = /\\$/;
  6491.     }
  6492.     }
  6493.  
  6494.     close (FC_FILE);
  6495.     return $result_vars . $result_rules . $comment;
  6496. }
  6497.  
  6498. # Like file_contents_with_transform, but no transform.
  6499. sub file_contents
  6500. {
  6501.     return &file_contents_with_transform ('', @_);
  6502. }
  6503.  
  6504. # Find all variable prefixes that are used for install directories.  A
  6505. # prefix `zar' qualifies iff:
  6506. # * `zardir' is a variable.
  6507. # * `zar_PRIMARY' is a variable.
  6508. sub am_primary_prefixes
  6509. {
  6510.     local ($primary, @prefixes) = @_;
  6511.  
  6512.     local (%valid, $varname);
  6513.     grep ($valid{$_} = 0, @prefixes);
  6514.     $valid{'EXTRA'} = 0;
  6515.     foreach $varname (keys %contents)
  6516.     {
  6517.     if ($varname =~ /^(.*)_$primary$/)
  6518.     {
  6519.         if (! defined $valid{$1}
  6520.         && ! &variable_defined ($1 . 'dir')
  6521.         # Note that a configure variable is always legitimate.
  6522.         # It is natural to name such variables after the
  6523.         # primary, so we explicitly allow it.
  6524.         && ! defined $configure_vars{$varname})
  6525.         {
  6526.         &am_line_error ($varname, "invalid variable \`$varname'");
  6527.         }
  6528.         else
  6529.         {
  6530.         # Ensure all extended prefixes are actually used.
  6531.         $valid{$1} = 1;
  6532.         }
  6533.     }
  6534.     }
  6535.  
  6536.     return %valid;
  6537. }
  6538.  
  6539. # Handle `where_HOW' variable magic.  Does all lookups, generates
  6540. # install code, and possibly generates code to define the primary
  6541. # variable.  The first argument is the name of the .am file to munge,
  6542. # the second argument is the primary variable (eg HEADERS), and all
  6543. # subsequent arguments are possible installation locations.  Returns
  6544. # list of all values of all _HOW targets.
  6545. #
  6546. # FIXME: this should be rewritten to be cleaner.  It should be broken
  6547. # up into multiple functions.
  6548. #
  6549. # Usage is: am_install_var (OPTION..., file, HOW, where...)
  6550. sub am_install_var
  6551. {
  6552.     local (@args) = @_;
  6553.  
  6554.     local ($do_clean) = 0;
  6555.     local ($do_require) = 1;
  6556.  
  6557.     local ($ltxform);
  6558.     if (defined $configure_vars{'LIBTOOL'})
  6559.     {
  6560.     # Transform '@LIBTOOL ...@' to '$(LIBTOOL) ...'
  6561.     $ltxform = 's/\@LIBTOOL([^\@]*)\@/\$(LIBTOOL) $1/;';
  6562.     }
  6563.     else
  6564.     {
  6565.     # Delete '@LIBTOOL ...@'
  6566.     $ltxform = 's/\@LIBTOOL([^\@]*)\@//;';
  6567.     }
  6568.  
  6569.     local ($cygxform);
  6570.     if (! $seen_exeext)
  6571.     {
  6572.     $cygxform = 's/\@EXEEXT\@//g;';
  6573.     }
  6574.     else
  6575.     {
  6576.     $cygxform = 's/\@EXEEXT\@/\$(EXEEXT)/g;';
  6577.     }
  6578.  
  6579.     while (@args)
  6580.     {
  6581.     if ($args[0] eq '-clean')
  6582.     {
  6583.         $do_clean = 1;
  6584.     }
  6585.     elsif ($args[0] eq '-noextra')
  6586.     {
  6587.         $do_require = 0;
  6588.     }
  6589.     elsif ($args[0] !~ /^-/)
  6590.     {
  6591.         last;
  6592.     }
  6593.     shift (@args);
  6594.     }
  6595.     local ($file, $primary, @prefixes) = @args;
  6596.  
  6597.     local (@used) = ();
  6598.     local (@result) = ();
  6599.  
  6600.     # Now that configure substitutions are allowed in where_HOW
  6601.     # variables, it is an error to actually define the primary.  We
  6602.     # allow `JAVA', as it is customarily used to mean the Java
  6603.     # interpreter.  This is but one of several Java hacks.
  6604.     &am_line_error ($primary, "\`$primary' is an anachronism")
  6605.     if &variable_defined ($primary) && $primary ne 'JAVA';
  6606.  
  6607.  
  6608.     # Look for misspellings.  It is an error to have a variable ending
  6609.     # in a "reserved" suffix whose prefix is unknown, eg
  6610.     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
  6611.     # variable of the same name (with "dir" appended) exists.  For
  6612.     # instance, if the variable "zardir" is defined, then
  6613.     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
  6614.     # flexibility in those cases which need it.  Perhaps it should be
  6615.     # disallowed in the Gnits case?  The problem is, sometimes it is
  6616.     # useful to put things in a subdir of eg pkgdatadir, perhaps even
  6617.     # for Gnitsoids.
  6618.     local (%valid) = &am_primary_prefixes ($primary, @prefixes);
  6619.  
  6620.     # If a primary includes a configure substitution, then the EXTRA_
  6621.     # form is required.  Otherwise we can't properly do our job.
  6622.     local ($require_extra);
  6623.     local ($warned_about_extra) = 0;
  6624.  
  6625.     local ($clean_file) = $file . '-clean';
  6626.     local ($one_name);
  6627.     local ($X);
  6628.     foreach $X (sort keys %valid)
  6629.     {
  6630.     $one_name = $X . '_' . $primary;
  6631.     if (&variable_defined ($one_name))
  6632.     {
  6633.         # Append actual contents of where_PRIMARY variable to
  6634.         # result.
  6635.         local ($rcurs);
  6636.         foreach $rcurs (&variable_value_as_list ($one_name, 'all'))
  6637.         {
  6638.         # Skip configure substitutions.  Possibly bogus.
  6639.         if ($rcurs =~ /^\@.*\@$/)
  6640.         {
  6641.             if ($X eq 'EXTRA')
  6642.             {
  6643.             if (! $warned_about_extra)
  6644.             {
  6645.                 $warned_about_extra = 1;
  6646.                 {
  6647.                 &am_line_error ($one_name,
  6648.                         "\`$one_name' contains configure substitution, but shouldn't");
  6649.                 }
  6650.             }
  6651.             }
  6652.             # Check here to make sure variables defined in
  6653.             # configure.in do not imply that EXTRA_PRIMARY
  6654.             # must be defined.
  6655.             elsif (! defined $configure_vars{$one_name})
  6656.             {
  6657.             $require_extra = $one_name
  6658.                 if $do_require;
  6659.             }
  6660.  
  6661.             next;
  6662.         }
  6663.  
  6664.         push (@result, $rcurs);
  6665.         }
  6666.  
  6667.         # "EXTRA" shouldn't be used when generating clean targets,
  6668.         # all, or install targets.
  6669.         if ($X eq 'EXTRA')
  6670.         {
  6671.         if (! $warned_about_extra && ! $do_require)
  6672.         {
  6673.             $warned_about_extra = 1;
  6674.             &am_line_error ($one_name,
  6675.                     "\`$one_name' should not be defined");
  6676.         }
  6677.         next;
  6678.         }
  6679.  
  6680.         # A blatant hack: we rewrite each _PROGRAMS primary to
  6681.         # include EXEEXT when in Cygwin32 mode.
  6682.         if ($seen_exeext && $primary eq 'PROGRAMS')
  6683.         {
  6684.         local (@conds) = &variable_conditions ($one_name);
  6685.         local (@one_binlist);
  6686.  
  6687.         # FIXME: this definitely loses aesthetically; it
  6688.         # redefines $ONE_NAME.  Instead we should arrange for
  6689.         # variable definitions to be output later, instead of
  6690.         # at scan time.
  6691.  
  6692.         if (! @conds)
  6693.         {
  6694.             @one_binlist = ();
  6695.             foreach $rcurs (&variable_value_as_list ($one_name, ''))
  6696.             {
  6697.             if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
  6698.             {
  6699.                 push (@one_binlist, $rcurs);
  6700.             }
  6701.             else
  6702.             {
  6703.                 push (@one_binlist, $rcurs . '$(EXEEXT)');
  6704.             }
  6705.             }
  6706.  
  6707.             delete $contents{$one_name};
  6708.             &define_pretty_variable ($one_name, '', @one_binlist);
  6709.         }
  6710.         else
  6711.         {
  6712.             local ($cond);
  6713.             local ($condvals) = '';
  6714.             foreach $cond (@conds)
  6715.             {
  6716.             @one_binlist = ();
  6717.             local (@condval) = &variable_value_as_list ($one_name,
  6718.                                     $cond);
  6719.             foreach $rcurs (@condval)
  6720.             {
  6721.                 if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
  6722.                 {
  6723.                 push (@one_binlist, $rcurs);
  6724.                 }
  6725.                 else
  6726.                 {
  6727.                 push (@one_binlist, $rcurs . '$(EXEEXT)');
  6728.                 }
  6729.             }
  6730.  
  6731.             push (@condvals, $cond);
  6732.             push (@condvals, join (' ', @one_binlist));
  6733.             }
  6734.  
  6735.             delete $contents{$one_name};
  6736.  
  6737.             while (@condvals)
  6738.             {
  6739.             $cond = shift (@condvals);
  6740.             local (@val) = split (' ', shift (@condvals));
  6741.             &define_pretty_variable ($one_name, $cond, @val);
  6742.             }
  6743.         }
  6744.         }
  6745.  
  6746.         if ($do_clean)
  6747.         {
  6748.         $output_rules .=
  6749.             &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go;'
  6750.                            . $cygxform,
  6751.                            $clean_file);
  6752.  
  6753.         push (@clean, $X . $primary);
  6754.         &push_phony_cleaners ($X . $primary);
  6755.         }
  6756.  
  6757.         if ($X eq 'check')
  6758.         {
  6759.         push (@check, '$(' . $one_name . ')');
  6760.         }
  6761.         else
  6762.         {
  6763.         push (@used, '$(' . $one_name . ')');
  6764.         }
  6765.         if ($X eq 'noinst' || $X eq 'check')
  6766.         {
  6767.         # Objects which don't get installed by default.
  6768.         next;
  6769.         }
  6770.  
  6771.         $output_rules .=
  6772.         &file_contents_with_transform ('s/\@DIR\@/' . $X . '/g;'
  6773.                            . $ltxform . $cygxform,
  6774.                            $file);
  6775.  
  6776.         push (@uninstall, 'uninstall-' . $X . $primary);
  6777.         push (@phony, 'uninstall-' . $X . $primary);
  6778.         push (@installdirs, '$(DESTDIR)$(' . $X . 'dir)');
  6779.         if (defined $exec_dir_p{$X} ? $exec_dir_p{$X} : ($X =~ /exec/))
  6780.         {
  6781.         push (@install_exec, 'install-' . $X . $primary);
  6782.         push (@phony, 'install-' . $X . $primary);
  6783.         }
  6784.         else
  6785.         {
  6786.         push (@install_data, 'install-' . $X . $primary);
  6787.         push (@phony, 'install-' . $X . $primary);
  6788.         }
  6789.     }
  6790.     }
  6791.  
  6792.     # The JAVA variable is used as the name of the Java interpreter.
  6793.     if (@used && $primary ne 'JAVA')
  6794.     {
  6795.     # Define it.
  6796.     &define_pretty_variable ($primary, '', @used);
  6797.     $output_vars .= "\n";
  6798.     }
  6799.  
  6800.     if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
  6801.     {
  6802.     &am_line_error ($require_extra,
  6803.             "\`$require_extra' contains configure substitution, but \`EXTRA_$primary' not defined");
  6804.     }
  6805.  
  6806.     # Push here because PRIMARY might be configure time determined.
  6807.     push (@all, '$(' . $primary . ')')
  6808.     if @used && $primary ne 'JAVA';
  6809.  
  6810.     return (@result);
  6811. }
  6812.  
  6813.  
  6814. ################################################################
  6815.  
  6816. # This variable is local to the "require file" set of functions.
  6817. @require_file_paths = ();
  6818.  
  6819. # Verify that the file must exist in the current directory.  Usage:
  6820. # require_file (isconfigure, line_number, strictness, file) strictness
  6821. # is the strictness level at which this file becomes required.  Must
  6822. # set require_file_paths before calling this function.
  6823. # require_file_paths is set to hold a single directory (the one in
  6824. # which the first file was found) before return.
  6825. sub require_file_internal
  6826. {
  6827.     local ($is_configure, $line, $mystrict, @files) = @_;
  6828.     local ($file, $fullfile);
  6829.     local ($found_it, $errfile, $errdir);
  6830.     local ($save_dir);
  6831.  
  6832.     foreach $file (@files)
  6833.     {
  6834.     $found_it = 0;
  6835.     foreach $dir (@require_file_paths)
  6836.     {
  6837.         if ($dir eq '.')
  6838.         {
  6839.         $fullfile = $relative_dir . "/" . $file;
  6840.         $errdir = $relative_dir unless $errdir;
  6841.         }
  6842.         else
  6843.         {
  6844.         $fullfile = $dir . "/" . $file;
  6845.         $errdir = $dir unless $errdir;
  6846.         }
  6847.  
  6848.         # Use different name for "error filename".  Otherwise on
  6849.         # an error the bad file will be reported as eg
  6850.         # `../../install-sh' when using the default
  6851.         # config_aux_path.
  6852.         $errfile = $errdir . '/' . $file;
  6853.  
  6854.         if (-f $fullfile)
  6855.         {
  6856.         $found_it = 1;
  6857.         # FIXME: Once again, special-case `.'.
  6858.         &push_dist_common ($file)
  6859.             if $dir eq $relative_dir || $dir eq '.';
  6860.         $save_dir = $dir;
  6861.         last;
  6862.         }
  6863.     }
  6864.  
  6865.     if ($found_it)
  6866.     {
  6867.         # Prune the path list.
  6868.         @require_file_paths = $save_dir;
  6869.     }
  6870.     else
  6871.     {
  6872.         if ($strictness >= $mystrict)
  6873.         {
  6874.         local ($trailer) = '';
  6875.         local ($suppress) = 0;
  6876.  
  6877.         # Only install missing files according to our desired
  6878.         # strictness level.
  6879.         local ($message) = "required file \`$errfile' not found";
  6880.         if ($add_missing)
  6881.         {
  6882.             $suppress = 1;
  6883.  
  6884.             # Maybe run libtoolize.
  6885.             if ($seen_libtool
  6886.             && grep ($_ eq $file, @libtoolize_files)
  6887.             && system ('libtoolize', '--automake'))
  6888.             {
  6889.             $message = "installing \`$errfile'";
  6890.             $suppress = 0;
  6891.             $trailer = "; cannot run \`libtoolize': $!";
  6892.             }
  6893.             elsif (-f ($am_dir . '/' . $file))
  6894.             {
  6895.             # Install the missing file.  Symlink if we
  6896.             # can, copy if we must.  Note: delete the file
  6897.             # first, in case it is a dangling symlink.
  6898.             $message = "installing \`$errfile'";
  6899.             # Windows Perl will hang if we try to delete a
  6900.             # file that doesn't exist.
  6901.             unlink ($errfile) if -f $errfile;
  6902.             if ($symlink_exists && ! $copy_missing)
  6903.             {
  6904.                 if (! symlink ($am_dir . '/' . $file, $errfile))
  6905.                 {
  6906.                 $suppress = 0;
  6907.                 $trailer = "; error while making link: $!\n";
  6908.                 }
  6909.             }
  6910.             elsif (! system ('cp', $am_dir . '/' . $file, $errfile))
  6911.             {
  6912.                 $suppress = 0;
  6913.                 $trailer = "\n    error while copying\n";
  6914.             }
  6915.             }
  6916.         }
  6917.  
  6918.         local ($save) = $exit_status;
  6919.         if ($is_configure)
  6920.         {
  6921.             # FIXME: allow actual file to be specified.
  6922.             &am_conf_line_error ('configure.in', $line,
  6923.                      "$message$trailer");
  6924.         }
  6925.         else
  6926.         {
  6927.             &am_line_error ($line, "$message$trailer");
  6928.         }
  6929.         $exit_status = $save if $suppress;
  6930.         }
  6931.     }
  6932.     }
  6933. }
  6934.  
  6935. # Like require_file_with_line, but error messages refer to
  6936. # configure.in, not the current Makefile.am.
  6937. sub require_file_with_conf_line
  6938. {
  6939.     @require_file_paths = '.';
  6940.     &require_file_internal (1, @_);
  6941. }
  6942.  
  6943. sub require_file_with_line
  6944. {
  6945.     @require_file_paths = '.';
  6946.     &require_file_internal (0, @_);
  6947. }
  6948.  
  6949. sub require_file
  6950. {
  6951.     @require_file_paths = '.';
  6952.     &require_file_internal (0, '', @_);
  6953. }
  6954.  
  6955. # Require a file that is also required by Autoconf.  Looks in
  6956. # configuration path, as specified by AC_CONFIG_AUX_DIR.
  6957. sub require_config_file
  6958. {
  6959.     @require_file_paths = @config_aux_path;
  6960.     &require_file_internal (1, '', @_);
  6961.     local ($dir) = $require_file_paths[0];
  6962.     @config_aux_path = @require_file_paths;
  6963.     if ($dir eq '.')
  6964.     {
  6965.     $config_aux_dir = '.';
  6966.     }
  6967.     else
  6968.     {
  6969.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  6970.     }
  6971. }
  6972.  
  6973. # Assumes that the line number is in Makefile.am.
  6974. sub require_conf_file_with_line
  6975. {
  6976.     @require_file_paths = @config_aux_path;
  6977.     &require_file_internal (0, @_);
  6978.     local ($dir) = $require_file_paths[0];
  6979.     @config_aux_path = @require_file_paths;
  6980.     if ($dir eq '.')
  6981.     {
  6982.     $config_aux_dir = '.';
  6983.     }
  6984.     else
  6985.     {
  6986.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  6987.     }
  6988. }
  6989.  
  6990. # Assumes that the line number is in Makefile.am.
  6991. sub require_conf_file_with_conf_line
  6992. {
  6993.     @require_file_paths = @config_aux_path;
  6994.     &require_file_internal (1, @_);
  6995.     local ($dir) = $require_file_paths[0];
  6996.     @config_aux_path = @require_file_paths;
  6997.     if ($dir eq '.')
  6998.     {
  6999.     $config_aux_dir = '.';
  7000.     }
  7001.     else
  7002.     {
  7003.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  7004.     }
  7005. }
  7006.  
  7007. ################################################################
  7008.  
  7009. # Push a list of files onto dist_common.
  7010. sub push_dist_common
  7011. {
  7012.     local (@files) = @_;
  7013.     local ($file);
  7014.  
  7015.     foreach $file (@files)
  7016.     {
  7017.     $dist_common{$file} = 1;
  7018.     }
  7019. }
  7020.  
  7021. # Push a list of clean targets onto phony.
  7022. sub push_phony_cleaners
  7023. {
  7024.     local ($base) = @_;
  7025.     local ($target);
  7026.     foreach $target ('mostly', 'dist', '', 'maintainer-')
  7027.     {
  7028.     push (@phony, $target . 'clean-' . $base);
  7029.     }
  7030. }
  7031.  
  7032. # Set strictness.
  7033. sub set_strictness
  7034. {
  7035.     $strictness_name = $_[0];
  7036.     if ($strictness_name eq 'gnu')
  7037.     {
  7038.     $strictness = $GNU;
  7039.     }
  7040.     elsif ($strictness_name eq 'gnits')
  7041.     {
  7042.     $strictness = $GNITS;
  7043.     }
  7044.     elsif ($strictness_name eq 'foreign')
  7045.     {
  7046.     $strictness = $FOREIGN;
  7047.     }
  7048.     else
  7049.     {
  7050.     die "automake: level \`$strictness_name' not recognized\n";
  7051.     }
  7052. }
  7053.  
  7054.  
  7055. ################################################################
  7056.  
  7057. # Return directory name of file.
  7058. sub dirname
  7059. {
  7060.     local ($file) = @_;
  7061.     local ($sub);
  7062.  
  7063.     ($sub = $file) =~ s,/+[^/]+$,,g;
  7064.     $sub = '.' if $sub eq $file;
  7065.     return $sub;
  7066. }
  7067.  
  7068. # Return file name of a file.
  7069. sub basename
  7070. {
  7071.     local ($file) = @_;
  7072.     local ($sub);
  7073.  
  7074.     ($sub = $file) =~s,^.*/+,,g;
  7075.     return $sub;
  7076. }
  7077.  
  7078. # Ensure a file exists.
  7079. sub create
  7080. {
  7081.     local ($file) = @_;
  7082.  
  7083.     open (TOUCH, ">> $file");
  7084.     close (TOUCH);
  7085. }
  7086.  
  7087. # Glob something.  Do this to avoid indentation screwups everywhere we
  7088. # want to glob.  Gross!
  7089. sub my_glob
  7090. {
  7091.     local ($pat) = @_;
  7092.     return <${pat}>;
  7093. }
  7094.  
  7095. ################################################################
  7096.  
  7097. # Print an error message and set exit status.
  7098. sub am_error
  7099. {
  7100.     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
  7101.     $exit_status = 1;
  7102. }
  7103.  
  7104. sub am_line_error
  7105. {
  7106.     local ($symbol, @args) = @_;
  7107.  
  7108.     if ($symbol && "$symbol" ne '-1')
  7109.     {
  7110.     local ($file) = "${am_file}.am";
  7111.  
  7112.     if ($symbol =~ /^\d+$/)
  7113.     {
  7114.         # SYMBOL is a line number, so just add the colon.
  7115.         $file .= ':' . $symbol;
  7116.     }
  7117.     elsif (defined $content_lines{$symbol})
  7118.     {
  7119.         # SYMBOL is a variable defined in Makefile.am, so add the
  7120.         # line number we saved from there.
  7121.         $file .= ':' . $content_lines{$symbol};
  7122.     }
  7123.     elsif (defined $configure_vars{$symbol})
  7124.     {
  7125.         # SYMBOL is a variable defined in configure.in, so add the
  7126.         # appropriate line number.
  7127.         $file = $configure_vars{$symbol};
  7128.     }
  7129.     else
  7130.     {
  7131.         # Couldn't find the line number.
  7132.     }
  7133.     warn $file, ": ", join (' ', @args), "\n";
  7134.     $exit_status = 1;
  7135.     }
  7136.     else
  7137.     {
  7138.     &am_error (@args);
  7139.     }
  7140. }
  7141.  
  7142. # Like am_error, but while scanning configure.in.
  7143. sub am_conf_error
  7144. {
  7145.     # FIXME: can run in subdirs.
  7146.     warn "automake: configure.in: ", join (' ', @_), "\n";
  7147.     $exit_status = 1;
  7148. }
  7149.  
  7150. # Error message with line number referring to configure.in.
  7151. sub am_conf_line_error
  7152. {
  7153.     local ($file, $line, @args) = @_;
  7154.  
  7155.     if ($line)
  7156.     {
  7157.     warn "$file: $line: ", join (' ', @args), "\n";
  7158.     $exit_status = 1;
  7159.     }
  7160.     else
  7161.     {
  7162.     &am_conf_error (@args);
  7163.     }
  7164. }
  7165.  
  7166. # Warning message with line number referring to configure.in.
  7167. # Does not affect exit_status
  7168. sub am_conf_line_warning
  7169. {
  7170.     local ($saved_exit_status) = $exit_status;
  7171.     &am_conf_line_error (@_);
  7172.     $exit_status = $saved_exit_status;
  7173. }
  7174.  
  7175. # Tell user where our aclocal.m4 is, but only once.
  7176. sub keyed_aclocal_warning
  7177. {
  7178.     local ($key) = @_;
  7179.     warn "automake: macro \`$key' can be generated by \`aclocal'\n";
  7180. }
  7181.  
  7182. # Print usage information.
  7183. sub usage
  7184. {
  7185.     print "Usage: automake [OPTION] ... [Makefile]...\n\n";
  7186.     print "Generate Makefile.in for autoconf from Makefile.am\n";
  7187.     print $USAGE;
  7188.     print "\nFiles which are automatically distributed, if found:\n";
  7189.     $~ = "USAGE_FORMAT";
  7190.     local ($last, $iter, @lcomm);
  7191.     $last = '';
  7192.     foreach $iter (sort ((@common_files, @common_sometimes)))
  7193.     {
  7194.     push (@lcomm, $iter) unless $iter eq $last;
  7195.     $last = $iter;
  7196.     }
  7197.  
  7198.     local ($one, $two, $three, $four, $i, $max);
  7199.     $max = int (($#lcomm + 1) / 4);
  7200.  
  7201.     for ($i = 0; $i < $max; ++$i)
  7202.     {
  7203.     $one = $lcomm[$i];
  7204.     $two = $lcomm[$max + $i];
  7205.     $three = $lcomm[2 * $max + $i];
  7206.     $four = $lcomm[3 * $max + $i];
  7207.     write;
  7208.     }
  7209.  
  7210.     local ($mod) = ($#lcomm + 1) % 4;
  7211.     if ($mod != 0)
  7212.     {
  7213.     $one = $lcomm[$max];
  7214.     $two = ($mod > 1) ? $lcomm[2 * $max] : '';
  7215.     $three = ($mod > 2) ? $lcomm[3 * $max] : '';
  7216.     $four = ($mod > 3) ? $lcomm[4 * $max] : '';
  7217.     write;
  7218.     }
  7219.  
  7220.     print "\nReport bugs to <bug-automake\@gnu.org>.\n";
  7221.  
  7222.     exit 0;
  7223. }
  7224.  
  7225. format USAGE_FORMAT =
  7226.   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  7227.   $one,               $two,               $three,             $four
  7228. .
  7229.